fdomain_fuchsia_mem/
fdomain_fuchsia_mem.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 fdomain_client::fidl::{ControlHandle as _, FDomainFlexibleIntoResult as _, Responder as _};
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9pub use fidl_fuchsia_mem__common::*;
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13/// A buffer for data whose size is not necessarily a multiple of the page
14/// size.
15///
16/// DEPRECATED: This type is superfluous and deprecated. Instead of using this type,
17/// use a zx.Handle:VMO object and store the size of the contents in the ZX_PROP_VMO_CONTENT_SIZE
18/// property.
19#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
20pub struct Buffer {
21    /// The vmo that contains the buffer.
22    pub vmo: fdomain_client::Vmo,
23    /// The number of bytes in the buffer.
24    ///
25    /// The content of the buffer begin at the start of the VMO and continue
26    /// for `size` bytes. To specify a range of bytes that do not start at
27    /// the beginning of the VMO, use `Range` rather than buffer.
28    ///
29    /// This size must not be greater than the physical size of the VMO.
30    pub size: u64,
31}
32
33impl fidl::Standalone<fdomain_client::fidl::FDomainResourceDialect> for Buffer {}
34
35/// A range of bytes within a VMO.
36#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
37pub struct Range {
38    /// The vmo that contains the bytes.
39    pub vmo: fdomain_client::Vmo,
40    /// The offset of the first byte within the range relative to the start of
41    /// the VMO.
42    ///
43    /// For example, if `offset` is zero, then the first byte in the range is
44    /// the first byte in the VMO.
45    pub offset: u64,
46    /// The number of bytes in the range.
47    ///
48    /// For example, if the offset is 3 and the size is 2, and the VMO starts
49    /// with "abcdefg...", then the range contains "de".
50    ///
51    /// The sum of the offset and the size must not be greater than the
52    /// physical size of the VMO.
53    pub size: u64,
54}
55
56impl fidl::Standalone<fdomain_client::fidl::FDomainResourceDialect> for Range {}
57
58/// Binary data that might be stored inline or in a VMO.
59///
60/// Useful for performance-sensitive protocols that sometimes receive small
61/// amounts of binary data (i.e., which is more efficient to provide using
62/// `bytes`) but also need to support arbitrary amounts of data (i.e., which
63/// need to be provided out-of-line in a `Buffer`).
64#[derive(Debug)]
65pub enum Data {
66    /// The binary data provided inline in the message.
67    Bytes(Vec<u8>),
68    /// The binary data provided out-of-line in a `Buffer`.
69    Buffer(Buffer),
70    #[doc(hidden)]
71    __SourceBreaking { unknown_ordinal: u64 },
72}
73
74/// Pattern that matches an unknown `Data` member.
75#[macro_export]
76macro_rules! DataUnknown {
77    () => {
78        _
79    };
80}
81
82// Custom PartialEq so that unknown variants are not equal to themselves.
83impl PartialEq for Data {
84    fn eq(&self, other: &Self) -> bool {
85        match (self, other) {
86            (Self::Bytes(x), Self::Bytes(y)) => *x == *y,
87            (Self::Buffer(x), Self::Buffer(y)) => *x == *y,
88            _ => false,
89        }
90    }
91}
92
93impl Data {
94    #[inline]
95    pub fn ordinal(&self) -> u64 {
96        match *self {
97            Self::Bytes(_) => 1,
98            Self::Buffer(_) => 2,
99            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
100        }
101    }
102
103    #[inline]
104    pub fn unknown_variant_for_testing() -> Self {
105        Self::__SourceBreaking { unknown_ordinal: 0 }
106    }
107
108    #[inline]
109    pub fn is_unknown(&self) -> bool {
110        match self {
111            Self::__SourceBreaking { .. } => true,
112            _ => false,
113        }
114    }
115}
116
117impl fidl::Standalone<fdomain_client::fidl::FDomainResourceDialect> for Data {}
118
119mod internal {
120    use super::*;
121
122    impl fidl::encoding::ResourceTypeMarker for Buffer {
123        type Borrowed<'a> = &'a mut Self;
124        fn take_or_borrow<'a>(
125            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
126        ) -> Self::Borrowed<'a> {
127            value
128        }
129    }
130
131    unsafe impl fidl::encoding::TypeMarker for Buffer {
132        type Owned = Self;
133
134        #[inline(always)]
135        fn inline_align(_context: fidl::encoding::Context) -> usize {
136            8
137        }
138
139        #[inline(always)]
140        fn inline_size(_context: fidl::encoding::Context) -> usize {
141            16
142        }
143    }
144
145    unsafe impl fidl::encoding::Encode<Buffer, fdomain_client::fidl::FDomainResourceDialect>
146        for &mut Buffer
147    {
148        #[inline]
149        unsafe fn encode(
150            self,
151            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
152            offset: usize,
153            _depth: fidl::encoding::Depth,
154        ) -> fidl::Result<()> {
155            encoder.debug_check_bounds::<Buffer>(offset);
156            // Delegate to tuple encoding.
157            fidl::encoding::Encode::<Buffer, fdomain_client::fidl::FDomainResourceDialect>::encode(
158                (
159                    <fidl::encoding::HandleType<
160                        fdomain_client::Vmo,
161                        { fidl::ObjectType::VMO.into_raw() },
162                        2147483648,
163                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
164                        &mut self.vmo
165                    ),
166                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.size),
167                ),
168                encoder,
169                offset,
170                _depth,
171            )
172        }
173    }
174    unsafe impl<
175            T0: fidl::encoding::Encode<
176                fidl::encoding::HandleType<
177                    fdomain_client::Vmo,
178                    { fidl::ObjectType::VMO.into_raw() },
179                    2147483648,
180                >,
181                fdomain_client::fidl::FDomainResourceDialect,
182            >,
183            T1: fidl::encoding::Encode<u64, fdomain_client::fidl::FDomainResourceDialect>,
184        > fidl::encoding::Encode<Buffer, fdomain_client::fidl::FDomainResourceDialect>
185        for (T0, T1)
186    {
187        #[inline]
188        unsafe fn encode(
189            self,
190            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
191            offset: usize,
192            depth: fidl::encoding::Depth,
193        ) -> fidl::Result<()> {
194            encoder.debug_check_bounds::<Buffer>(offset);
195            // Zero out padding regions. There's no need to apply masks
196            // because the unmasked parts will be overwritten by fields.
197            unsafe {
198                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
199                (ptr as *mut u64).write_unaligned(0);
200            }
201            // Write the fields.
202            self.0.encode(encoder, offset + 0, depth)?;
203            self.1.encode(encoder, offset + 8, depth)?;
204            Ok(())
205        }
206    }
207
208    impl fidl::encoding::Decode<Self, fdomain_client::fidl::FDomainResourceDialect> for Buffer {
209        #[inline(always)]
210        fn new_empty() -> Self {
211            Self {
212                vmo: fidl::new_empty!(fidl::encoding::HandleType<fdomain_client::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fdomain_client::fidl::FDomainResourceDialect),
213                size: fidl::new_empty!(u64, fdomain_client::fidl::FDomainResourceDialect),
214            }
215        }
216
217        #[inline]
218        unsafe fn decode(
219            &mut self,
220            decoder: &mut fidl::encoding::Decoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
221            offset: usize,
222            _depth: fidl::encoding::Depth,
223        ) -> fidl::Result<()> {
224            decoder.debug_check_bounds::<Self>(offset);
225            // Verify that padding bytes are zero.
226            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
227            let padval = unsafe { (ptr as *const u64).read_unaligned() };
228            let mask = 0xffffffff00000000u64;
229            let maskedval = padval & mask;
230            if maskedval != 0 {
231                return Err(fidl::Error::NonZeroPadding {
232                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
233                });
234            }
235            fidl::decode!(fidl::encoding::HandleType<fdomain_client::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fdomain_client::fidl::FDomainResourceDialect, &mut self.vmo, decoder, offset + 0, _depth)?;
236            fidl::decode!(
237                u64,
238                fdomain_client::fidl::FDomainResourceDialect,
239                &mut self.size,
240                decoder,
241                offset + 8,
242                _depth
243            )?;
244            Ok(())
245        }
246    }
247
248    impl fidl::encoding::ResourceTypeMarker for Range {
249        type Borrowed<'a> = &'a mut Self;
250        fn take_or_borrow<'a>(
251            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
252        ) -> Self::Borrowed<'a> {
253            value
254        }
255    }
256
257    unsafe impl fidl::encoding::TypeMarker for Range {
258        type Owned = Self;
259
260        #[inline(always)]
261        fn inline_align(_context: fidl::encoding::Context) -> usize {
262            8
263        }
264
265        #[inline(always)]
266        fn inline_size(_context: fidl::encoding::Context) -> usize {
267            24
268        }
269    }
270
271    unsafe impl fidl::encoding::Encode<Range, fdomain_client::fidl::FDomainResourceDialect>
272        for &mut Range
273    {
274        #[inline]
275        unsafe fn encode(
276            self,
277            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
278            offset: usize,
279            _depth: fidl::encoding::Depth,
280        ) -> fidl::Result<()> {
281            encoder.debug_check_bounds::<Range>(offset);
282            // Delegate to tuple encoding.
283            fidl::encoding::Encode::<Range, fdomain_client::fidl::FDomainResourceDialect>::encode(
284                (
285                    <fidl::encoding::HandleType<
286                        fdomain_client::Vmo,
287                        { fidl::ObjectType::VMO.into_raw() },
288                        2147483648,
289                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
290                        &mut self.vmo
291                    ),
292                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.offset),
293                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.size),
294                ),
295                encoder,
296                offset,
297                _depth,
298            )
299        }
300    }
301    unsafe impl<
302            T0: fidl::encoding::Encode<
303                fidl::encoding::HandleType<
304                    fdomain_client::Vmo,
305                    { fidl::ObjectType::VMO.into_raw() },
306                    2147483648,
307                >,
308                fdomain_client::fidl::FDomainResourceDialect,
309            >,
310            T1: fidl::encoding::Encode<u64, fdomain_client::fidl::FDomainResourceDialect>,
311            T2: fidl::encoding::Encode<u64, fdomain_client::fidl::FDomainResourceDialect>,
312        > fidl::encoding::Encode<Range, fdomain_client::fidl::FDomainResourceDialect>
313        for (T0, T1, T2)
314    {
315        #[inline]
316        unsafe fn encode(
317            self,
318            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
319            offset: usize,
320            depth: fidl::encoding::Depth,
321        ) -> fidl::Result<()> {
322            encoder.debug_check_bounds::<Range>(offset);
323            // Zero out padding regions. There's no need to apply masks
324            // because the unmasked parts will be overwritten by fields.
325            unsafe {
326                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
327                (ptr as *mut u64).write_unaligned(0);
328            }
329            // Write the fields.
330            self.0.encode(encoder, offset + 0, depth)?;
331            self.1.encode(encoder, offset + 8, depth)?;
332            self.2.encode(encoder, offset + 16, depth)?;
333            Ok(())
334        }
335    }
336
337    impl fidl::encoding::Decode<Self, fdomain_client::fidl::FDomainResourceDialect> for Range {
338        #[inline(always)]
339        fn new_empty() -> Self {
340            Self {
341                vmo: fidl::new_empty!(fidl::encoding::HandleType<fdomain_client::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fdomain_client::fidl::FDomainResourceDialect),
342                offset: fidl::new_empty!(u64, fdomain_client::fidl::FDomainResourceDialect),
343                size: fidl::new_empty!(u64, fdomain_client::fidl::FDomainResourceDialect),
344            }
345        }
346
347        #[inline]
348        unsafe fn decode(
349            &mut self,
350            decoder: &mut fidl::encoding::Decoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
351            offset: usize,
352            _depth: fidl::encoding::Depth,
353        ) -> fidl::Result<()> {
354            decoder.debug_check_bounds::<Self>(offset);
355            // Verify that padding bytes are zero.
356            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
357            let padval = unsafe { (ptr as *const u64).read_unaligned() };
358            let mask = 0xffffffff00000000u64;
359            let maskedval = padval & mask;
360            if maskedval != 0 {
361                return Err(fidl::Error::NonZeroPadding {
362                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
363                });
364            }
365            fidl::decode!(fidl::encoding::HandleType<fdomain_client::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fdomain_client::fidl::FDomainResourceDialect, &mut self.vmo, decoder, offset + 0, _depth)?;
366            fidl::decode!(
367                u64,
368                fdomain_client::fidl::FDomainResourceDialect,
369                &mut self.offset,
370                decoder,
371                offset + 8,
372                _depth
373            )?;
374            fidl::decode!(
375                u64,
376                fdomain_client::fidl::FDomainResourceDialect,
377                &mut self.size,
378                decoder,
379                offset + 16,
380                _depth
381            )?;
382            Ok(())
383        }
384    }
385
386    impl fidl::encoding::ResourceTypeMarker for Data {
387        type Borrowed<'a> = &'a mut Self;
388        fn take_or_borrow<'a>(
389            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
390        ) -> Self::Borrowed<'a> {
391            value
392        }
393    }
394
395    unsafe impl fidl::encoding::TypeMarker for Data {
396        type Owned = Self;
397
398        #[inline(always)]
399        fn inline_align(_context: fidl::encoding::Context) -> usize {
400            8
401        }
402
403        #[inline(always)]
404        fn inline_size(_context: fidl::encoding::Context) -> usize {
405            16
406        }
407    }
408
409    unsafe impl fidl::encoding::Encode<Data, fdomain_client::fidl::FDomainResourceDialect>
410        for &mut Data
411    {
412        #[inline]
413        unsafe fn encode(
414            self,
415            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
416            offset: usize,
417            _depth: fidl::encoding::Depth,
418        ) -> fidl::Result<()> {
419            encoder.debug_check_bounds::<Data>(offset);
420            encoder.write_num::<u64>(self.ordinal(), offset);
421            match self {
422            Data::Bytes(ref val) => {
423                fidl::encoding::encode_in_envelope::<fidl::encoding::UnboundedVector<u8>, fdomain_client::fidl::FDomainResourceDialect>(
424                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(val),
425                    encoder, offset + 8, _depth
426                )
427            }
428            Data::Buffer(ref mut val) => {
429                fidl::encoding::encode_in_envelope::<Buffer, fdomain_client::fidl::FDomainResourceDialect>(
430                    <Buffer as fidl::encoding::ResourceTypeMarker>::take_or_borrow(val),
431                    encoder, offset + 8, _depth
432                )
433            }
434            Data::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
435        }
436        }
437    }
438
439    impl fidl::encoding::Decode<Self, fdomain_client::fidl::FDomainResourceDialect> for Data {
440        #[inline(always)]
441        fn new_empty() -> Self {
442            Self::__SourceBreaking { unknown_ordinal: 0 }
443        }
444
445        #[inline]
446        unsafe fn decode(
447            &mut self,
448            decoder: &mut fidl::encoding::Decoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
449            offset: usize,
450            mut depth: fidl::encoding::Depth,
451        ) -> fidl::Result<()> {
452            decoder.debug_check_bounds::<Self>(offset);
453            #[allow(unused_variables)]
454            let next_out_of_line = decoder.next_out_of_line();
455            let handles_before = decoder.remaining_handles();
456            let (ordinal, inlined, num_bytes, num_handles) =
457                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
458
459            let member_inline_size = match ordinal {
460                1 => {
461                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::TypeMarker>::inline_size(
462                        decoder.context,
463                    )
464                }
465                2 => <Buffer as fidl::encoding::TypeMarker>::inline_size(decoder.context),
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 Data::Bytes(_) = self {
485                        // Do nothing, read the value into the object
486                    } else {
487                        // Initialize `self` to the right variant
488                        *self = Data::Bytes(fidl::new_empty!(
489                            fidl::encoding::UnboundedVector<u8>,
490                            fdomain_client::fidl::FDomainResourceDialect
491                        ));
492                    }
493                    #[allow(irrefutable_let_patterns)]
494                    if let Data::Bytes(ref mut val) = self {
495                        fidl::decode!(
496                            fidl::encoding::UnboundedVector<u8>,
497                            fdomain_client::fidl::FDomainResourceDialect,
498                            val,
499                            decoder,
500                            _inner_offset,
501                            depth
502                        )?;
503                    } else {
504                        unreachable!()
505                    }
506                }
507                2 => {
508                    #[allow(irrefutable_let_patterns)]
509                    if let Data::Buffer(_) = self {
510                        // Do nothing, read the value into the object
511                    } else {
512                        // Initialize `self` to the right variant
513                        *self = Data::Buffer(fidl::new_empty!(
514                            Buffer,
515                            fdomain_client::fidl::FDomainResourceDialect
516                        ));
517                    }
518                    #[allow(irrefutable_let_patterns)]
519                    if let Data::Buffer(ref mut val) = self {
520                        fidl::decode!(
521                            Buffer,
522                            fdomain_client::fidl::FDomainResourceDialect,
523                            val,
524                            decoder,
525                            _inner_offset,
526                            depth
527                        )?;
528                    } else {
529                        unreachable!()
530                    }
531                }
532                #[allow(deprecated)]
533                ordinal => {
534                    for _ in 0..num_handles {
535                        decoder.drop_next_handle()?;
536                    }
537                    *self = Data::__SourceBreaking { unknown_ordinal: ordinal };
538                }
539            }
540            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
541                return Err(fidl::Error::InvalidNumBytesInEnvelope);
542            }
543            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
544                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
545            }
546            Ok(())
547        }
548    }
549}