| // WARNING: This file is machine generated by fidlgen. |
| |
| // fidl_experiment = output_index_json |
| |
| #![warn(clippy::all)] |
| #![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)] |
| |
| use bitflags::bitflags; |
| use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect}; |
| use futures::future::{self, MaybeDone, TryFutureExt}; |
| use zx_status; |
| |
| pub const BOOL: bool = true; |
| |
| pub const FLOAT32: f32 = 3.14159; |
| |
| pub const FLOAT64: f64 = 3.14159; |
| |
| pub const INT16: i16 = 4; |
| |
| pub const INT32: i32 = 4; |
| |
| pub const INT64: i64 = 4; |
| |
| pub const INT8: i8 = 4; |
| |
| pub const STRING: &str = "string"; |
| |
| pub const UINT16: u16 = 4; |
| |
| pub const UINT32: u32 = 4; |
| |
| pub const UINT64: u64 = 4; |
| |
| pub const UINT8: u8 = 4; |
| |
| pub const BITS_PRIMITIVE_VAL: u32 = BitsType::VALUE.bits() as u32; |
| |
| pub const BITS_VAL: BitsType = BitsType::VALUE; |
| |
| pub const ENUM_PRIMITIVE_VAL: i32 = EnumType::Value.into_primitive() as i32; |
| |
| pub const ENUM_VAL: EnumType = EnumType::Value; |
| |
| pub const OR_RESULT: BitsType = BitsType::from_bits_truncate(7); |
| |
| pub const OR_RESULT_PRIMITIVE_VAL: u32 = 5; |
| |
| bitflags! { |
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| pub struct Bits: u32 { |
| const B = 8; |
| } |
| } |
| |
| impl Bits {} |
| |
| bitflags! { |
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| pub struct BitsType: u32 { |
| const VALUE = 1; |
| const SECOND_VALUE = UINT32 as u32; |
| const THIRD_VALUE = 2; |
| } |
| } |
| |
| impl BitsType {} |
| |
| #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| #[repr(u32)] |
| pub enum Enum { |
| E = 170, |
| } |
| |
| impl Enum { |
| #[inline] |
| pub fn from_primitive(prim: u32) -> Option<Self> { |
| match prim { |
| 170 => Some(Self::E), |
| _ => None, |
| } |
| } |
| |
| #[inline] |
| pub const fn into_primitive(self) -> u32 { |
| self as u32 |
| } |
| } |
| |
| #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| #[repr(i32)] |
| pub enum EnumType { |
| Value = 3, |
| SecondValue = 4, |
| } |
| |
| impl EnumType { |
| #[inline] |
| pub fn from_primitive(prim: i32) -> Option<Self> { |
| match prim { |
| 3 => Some(Self::Value), |
| 4 => Some(Self::SecondValue), |
| _ => None, |
| } |
| } |
| |
| #[inline] |
| pub const fn into_primitive(self) -> i32 { |
| self as i32 |
| } |
| } |
| |
| #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| pub struct Struct { |
| pub int64_with_default: i64, |
| pub string_with_default: String, |
| pub bool_with_default: bool, |
| pub enum_with_default: Enum, |
| pub bits_with_default: Bits, |
| } |
| |
| impl fidl::Persistable for Struct {} |
| |
| mod internal { |
| use super::*; |
| unsafe impl fidl::encoding::TypeMarker for Bits { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| 4 |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| 4 |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for Bits { |
| type Borrowed<'a> = Self; |
| #[inline(always)] |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| *value |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Bits { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Self>(offset); |
| if self.bits() & Self::all().bits() != self.bits() { |
| return Err(fidl::Error::InvalidBitsValue); |
| } |
| encoder.write_num(self.bits(), offset); |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Bits { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::empty() |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| let prim = decoder.read_num::<u32>(offset); |
| *self = Self::from_bits(prim).ok_or(fidl::Error::InvalidBitsValue)?; |
| Ok(()) |
| } |
| } |
| unsafe impl fidl::encoding::TypeMarker for BitsType { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| 4 |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| 4 |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for BitsType { |
| type Borrowed<'a> = Self; |
| #[inline(always)] |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| *value |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for BitsType { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Self>(offset); |
| if self.bits() & Self::all().bits() != self.bits() { |
| return Err(fidl::Error::InvalidBitsValue); |
| } |
| encoder.write_num(self.bits(), offset); |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BitsType { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::empty() |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| let prim = decoder.read_num::<u32>(offset); |
| *self = Self::from_bits(prim).ok_or(fidl::Error::InvalidBitsValue)?; |
| Ok(()) |
| } |
| } |
| unsafe impl fidl::encoding::TypeMarker for Enum { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| std::mem::align_of::<u32>() |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| std::mem::size_of::<u32>() |
| } |
| |
| #[inline(always)] |
| fn encode_is_copy() -> bool { |
| true |
| } |
| |
| #[inline(always)] |
| fn decode_is_copy() -> bool { |
| false |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for Enum { |
| type Borrowed<'a> = Self; |
| #[inline(always)] |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| *value |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Enum { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Self>(offset); |
| encoder.write_num(self.into_primitive(), offset); |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Enum { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::E |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| let prim = decoder.read_num::<u32>(offset); |
| |
| *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?; |
| Ok(()) |
| } |
| } |
| unsafe impl fidl::encoding::TypeMarker for EnumType { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| std::mem::align_of::<i32>() |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| std::mem::size_of::<i32>() |
| } |
| |
| #[inline(always)] |
| fn encode_is_copy() -> bool { |
| true |
| } |
| |
| #[inline(always)] |
| fn decode_is_copy() -> bool { |
| false |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for EnumType { |
| type Borrowed<'a> = Self; |
| #[inline(always)] |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| *value |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for EnumType { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Self>(offset); |
| encoder.write_num(self.into_primitive(), offset); |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for EnumType { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::Value |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| let prim = decoder.read_num::<i32>(offset); |
| |
| *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?; |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for Struct { |
| type Borrowed<'a> = &'a Self; |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for Struct { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| 8 |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| 40 |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Struct, D> for &Struct { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Struct>(offset); |
| // Delegate to tuple encoding. |
| fidl::encoding::Encode::<Struct, D>::encode( |
| ( |
| <i64 as fidl::encoding::ValueTypeMarker>::borrow(&self.int64_with_default), |
| <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow( |
| &self.string_with_default, |
| ), |
| <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.bool_with_default), |
| <Enum as fidl::encoding::ValueTypeMarker>::borrow(&self.enum_with_default), |
| <Bits as fidl::encoding::ValueTypeMarker>::borrow(&self.bits_with_default), |
| ), |
| encoder, |
| offset, |
| _depth, |
| ) |
| } |
| } |
| unsafe impl< |
| D: fidl::encoding::ResourceDialect, |
| T0: fidl::encoding::Encode<i64, D>, |
| T1: fidl::encoding::Encode<fidl::encoding::UnboundedString, D>, |
| T2: fidl::encoding::Encode<bool, D>, |
| T3: fidl::encoding::Encode<Enum, D>, |
| T4: fidl::encoding::Encode<Bits, D>, |
| > fidl::encoding::Encode<Struct, D> for (T0, T1, T2, T3, T4) |
| { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Struct>(offset); |
| // Zero out padding regions. There's no need to apply masks |
| // because the unmasked parts will be overwritten by fields. |
| unsafe { |
| let ptr = encoder.buf.as_mut_ptr().add(offset).offset(24); |
| (ptr as *mut u64).write_unaligned(0); |
| } |
| unsafe { |
| let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32); |
| (ptr as *mut u64).write_unaligned(0); |
| } |
| // Write the fields. |
| self.0.encode(encoder, offset + 0, depth)?; |
| self.1.encode(encoder, offset + 8, depth)?; |
| self.2.encode(encoder, offset + 24, depth)?; |
| self.3.encode(encoder, offset + 28, depth)?; |
| self.4.encode(encoder, offset + 32, depth)?; |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Struct { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self { |
| int64_with_default: fidl::new_empty!(i64, D), |
| string_with_default: fidl::new_empty!(fidl::encoding::UnboundedString, D), |
| bool_with_default: fidl::new_empty!(bool, D), |
| enum_with_default: fidl::new_empty!(Enum, D), |
| bits_with_default: fidl::new_empty!(Bits, D), |
| } |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| // Verify that padding bytes are zero. |
| let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(24) }; |
| let padval = unsafe { (ptr as *const u64).read_unaligned() }; |
| let mask = 0xffffff00u64; |
| let maskedval = padval & mask; |
| if maskedval != 0 { |
| return Err(fidl::Error::NonZeroPadding { |
| padding_start: offset + 24 + ((mask as u64).trailing_zeros() / 8) as usize, |
| }); |
| } |
| let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) }; |
| let padval = unsafe { (ptr as *const u64).read_unaligned() }; |
| let mask = 0xffffffff00000000u64; |
| let maskedval = padval & mask; |
| if maskedval != 0 { |
| return Err(fidl::Error::NonZeroPadding { |
| padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize, |
| }); |
| } |
| fidl::decode!(i64, D, &mut self.int64_with_default, decoder, offset + 0, _depth)?; |
| fidl::decode!( |
| fidl::encoding::UnboundedString, |
| D, |
| &mut self.string_with_default, |
| decoder, |
| offset + 8, |
| _depth |
| )?; |
| fidl::decode!(bool, D, &mut self.bool_with_default, decoder, offset + 24, _depth)?; |
| fidl::decode!(Enum, D, &mut self.enum_with_default, decoder, offset + 28, _depth)?; |
| fidl::decode!(Bits, D, &mut self.bits_with_default, decoder, offset + 32, _depth)?; |
| Ok(()) |
| } |
| } |
| } |