| // 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 type Alias = u32; |
| |
| pub const EXAMPLE_CONST: u32 = 0; |
| |
| bitflags! { |
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| pub struct ExampleBits: u32 { |
| const MEMBER = 1; |
| } |
| } |
| |
| impl ExampleBits {} |
| |
| #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| #[repr(u32)] |
| pub enum ExampleEnum { |
| Member = 1, |
| } |
| |
| impl ExampleEnum { |
| #[inline] |
| pub fn from_primitive(prim: u32) -> Option<Self> { |
| match prim { |
| 1 => Some(Self::Member), |
| _ => None, |
| } |
| } |
| |
| #[inline] |
| pub const fn into_primitive(self) -> u32 { |
| self as u32 |
| } |
| } |
| |
| #[derive(Clone, Debug, PartialEq)] |
| pub struct ExampleProtocolMethodRequest { |
| pub arg: fidl_test_exampleusing__common::Empty, |
| } |
| |
| impl fidl::Persistable for ExampleProtocolMethodRequest {} |
| |
| #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| #[repr(C)] |
| pub struct ExampleStruct { |
| pub member: u32, |
| } |
| |
| impl fidl::Persistable for ExampleStruct {} |
| |
| #[derive(Clone, Debug, Default, PartialEq)] |
| pub struct ExampleTable { |
| pub member: Option<u32>, |
| #[doc(hidden)] |
| pub __source_breaking: fidl::marker::SourceBreaking, |
| } |
| |
| impl fidl::Persistable for ExampleTable {} |
| |
| #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| pub enum ExampleUnion { |
| Variant(u32), |
| } |
| |
| impl ExampleUnion { |
| #[inline] |
| pub fn ordinal(&self) -> u64 { |
| match *self { |
| Self::Variant(_) => 1, |
| } |
| } |
| } |
| |
| impl fidl::Persistable for ExampleUnion {} |
| |
| pub mod example_protocol_ordinals { |
| pub const METHOD: u64 = 0x53978e6fc7476749; |
| } |
| |
| mod internal { |
| use super::*; |
| unsafe impl fidl::encoding::TypeMarker for ExampleBits { |
| 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 ExampleBits { |
| 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 ExampleBits { |
| #[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 ExampleBits { |
| #[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 ExampleEnum { |
| 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 ExampleEnum { |
| 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 ExampleEnum { |
| #[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 ExampleEnum { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::Member |
| } |
| |
| #[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(()) |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for ExampleProtocolMethodRequest { |
| type Borrowed<'a> = &'a Self; |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for ExampleProtocolMethodRequest { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| 1 |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| 1 |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> |
| fidl::encoding::Encode<ExampleProtocolMethodRequest, D> for &ExampleProtocolMethodRequest |
| { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<ExampleProtocolMethodRequest>(offset); |
| // Delegate to tuple encoding. |
| fidl::encoding::Encode::<ExampleProtocolMethodRequest, D>::encode( |
| ( |
| <fidl_test_exampleusing__common::Empty as fidl::encoding::ValueTypeMarker>::borrow(&self.arg), |
| ), |
| encoder, offset, _depth |
| ) |
| } |
| } |
| unsafe impl< |
| D: fidl::encoding::ResourceDialect, |
| T0: fidl::encoding::Encode<fidl_test_exampleusing__common::Empty, D>, |
| > fidl::encoding::Encode<ExampleProtocolMethodRequest, D> for (T0,) |
| { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<ExampleProtocolMethodRequest>(offset); |
| // Zero out padding regions. There's no need to apply masks |
| // because the unmasked parts will be overwritten by fields. |
| // Write the fields. |
| self.0.encode(encoder, offset + 0, depth)?; |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> |
| for ExampleProtocolMethodRequest |
| { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self { arg: fidl::new_empty!(fidl_test_exampleusing__common::Empty, 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. |
| fidl::decode!( |
| fidl_test_exampleusing__common::Empty, |
| D, |
| &mut self.arg, |
| decoder, |
| offset + 0, |
| _depth |
| )?; |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for ExampleStruct { |
| type Borrowed<'a> = &'a Self; |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for ExampleStruct { |
| 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 |
| } |
| #[inline(always)] |
| fn encode_is_copy() -> bool { |
| true |
| } |
| |
| #[inline(always)] |
| fn decode_is_copy() -> bool { |
| true |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ExampleStruct, D> |
| for &ExampleStruct |
| { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<ExampleStruct>(offset); |
| unsafe { |
| // Copy the object into the buffer. |
| let buf_ptr = encoder.buf.as_mut_ptr().add(offset); |
| (buf_ptr as *mut ExampleStruct) |
| .write_unaligned((self as *const ExampleStruct).read()); |
| // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be |
| // done second because the memcpy will write garbage to these bytes. |
| } |
| Ok(()) |
| } |
| } |
| unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u32, D>> |
| fidl::encoding::Encode<ExampleStruct, D> for (T0,) |
| { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<ExampleStruct>(offset); |
| // Zero out padding regions. There's no need to apply masks |
| // because the unmasked parts will be overwritten by fields. |
| // Write the fields. |
| self.0.encode(encoder, offset + 0, depth)?; |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ExampleStruct { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self { member: fidl::new_empty!(u32, 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); |
| let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) }; |
| // Verify that padding bytes are zero. |
| // Copy from the buffer into the object. |
| unsafe { |
| std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 4); |
| } |
| Ok(()) |
| } |
| } |
| |
| impl ExampleTable { |
| #[inline(always)] |
| fn max_ordinal_present(&self) -> u64 { |
| if let Some(_) = self.member { |
| return 1; |
| } |
| 0 |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for ExampleTable { |
| type Borrowed<'a> = &'a Self; |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for ExampleTable { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| 8 |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| 16 |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ExampleTable, D> |
| for &ExampleTable |
| { |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| mut depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<ExampleTable>(offset); |
| // Vector header |
| let max_ordinal: u64 = self.max_ordinal_present(); |
| encoder.write_num(max_ordinal, offset); |
| encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8); |
| // Calling encoder.out_of_line_offset(0) is not allowed. |
| if max_ordinal == 0 { |
| return Ok(()); |
| } |
| depth.increment()?; |
| let envelope_size = 8; |
| let bytes_len = max_ordinal as usize * envelope_size; |
| #[allow(unused_variables)] |
| let offset = encoder.out_of_line_offset(bytes_len); |
| let mut _prev_end_offset: usize = 0; |
| if 1 > max_ordinal { |
| return Ok(()); |
| } |
| |
| // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes |
| // are envelope_size bytes. |
| let cur_offset: usize = (1 - 1) * envelope_size; |
| |
| // Zero reserved fields. |
| encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset); |
| |
| // Safety: |
| // - bytes_len is calculated to fit envelope_size*max(member.ordinal). |
| // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes |
| // envelope_size bytes, there is always sufficient room. |
| fidl::encoding::encode_in_envelope_optional::<u32, D>( |
| self.member.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow), |
| encoder, |
| offset + cur_offset, |
| depth, |
| )?; |
| |
| _prev_end_offset = cur_offset + envelope_size; |
| |
| Ok(()) |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ExampleTable { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::default() |
| } |
| |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| mut depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| let len = match fidl::encoding::decode_vector_header(decoder, offset)? { |
| None => return Err(fidl::Error::NotNullable), |
| Some(len) => len, |
| }; |
| // Calling decoder.out_of_line_offset(0) is not allowed. |
| if len == 0 { |
| return Ok(()); |
| }; |
| depth.increment()?; |
| let envelope_size = 8; |
| let bytes_len = len * envelope_size; |
| let offset = decoder.out_of_line_offset(bytes_len)?; |
| // Decode the envelope for each type. |
| let mut _next_ordinal_to_read = 0; |
| let mut next_offset = offset; |
| let end_offset = offset + bytes_len; |
| _next_ordinal_to_read += 1; |
| if next_offset >= end_offset { |
| return Ok(()); |
| } |
| |
| // Decode unknown envelopes for gaps in ordinals. |
| while _next_ordinal_to_read < 1 { |
| fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?; |
| _next_ordinal_to_read += 1; |
| next_offset += envelope_size; |
| } |
| |
| let next_out_of_line = decoder.next_out_of_line(); |
| let handles_before = decoder.remaining_handles(); |
| if let Some((inlined, num_bytes, num_handles)) = |
| fidl::encoding::decode_envelope_header(decoder, next_offset)? |
| { |
| let member_inline_size = |
| <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context); |
| if inlined != (member_inline_size <= 4) { |
| return Err(fidl::Error::InvalidInlineBitInEnvelope); |
| } |
| let inner_offset; |
| let mut inner_depth = depth.clone(); |
| if inlined { |
| decoder.check_inline_envelope_padding(next_offset, member_inline_size)?; |
| inner_offset = next_offset; |
| } else { |
| inner_offset = decoder.out_of_line_offset(member_inline_size)?; |
| inner_depth.increment()?; |
| } |
| let val_ref = self.member.get_or_insert_with(|| fidl::new_empty!(u32, D)); |
| fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?; |
| if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) |
| { |
| return Err(fidl::Error::InvalidNumBytesInEnvelope); |
| } |
| if handles_before != decoder.remaining_handles() + (num_handles as usize) { |
| return Err(fidl::Error::InvalidNumHandlesInEnvelope); |
| } |
| } |
| |
| next_offset += envelope_size; |
| |
| // Decode the remaining unknown envelopes. |
| while next_offset < end_offset { |
| _next_ordinal_to_read += 1; |
| fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?; |
| next_offset += envelope_size; |
| } |
| |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for ExampleUnion { |
| type Borrowed<'a> = &'a Self; |
| fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for ExampleUnion { |
| type Owned = Self; |
| |
| #[inline(always)] |
| fn inline_align(_context: fidl::encoding::Context) -> usize { |
| 8 |
| } |
| |
| #[inline(always)] |
| fn inline_size(_context: fidl::encoding::Context) -> usize { |
| 16 |
| } |
| } |
| |
| unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ExampleUnion, D> |
| for &ExampleUnion |
| { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_, D>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<ExampleUnion>(offset); |
| encoder.write_num::<u64>(self.ordinal(), offset); |
| match self { |
| ExampleUnion::Variant(ref val) => fidl::encoding::encode_in_envelope::<u32, D>( |
| <u32 as fidl::encoding::ValueTypeMarker>::borrow(val), |
| encoder, |
| offset + 8, |
| _depth, |
| ), |
| } |
| } |
| } |
| |
| impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ExampleUnion { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::Variant(fidl::new_empty!(u32, D)) |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_, D>, |
| offset: usize, |
| mut depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| decoder.debug_check_bounds::<Self>(offset); |
| #[allow(unused_variables)] |
| let next_out_of_line = decoder.next_out_of_line(); |
| let handles_before = decoder.remaining_handles(); |
| let (ordinal, inlined, num_bytes, num_handles) = |
| fidl::encoding::decode_union_inline_portion(decoder, offset)?; |
| |
| let member_inline_size = match ordinal { |
| 1 => <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context), |
| _ => return Err(fidl::Error::UnknownUnionTag), |
| }; |
| |
| if inlined != (member_inline_size <= 4) { |
| return Err(fidl::Error::InvalidInlineBitInEnvelope); |
| } |
| let _inner_offset; |
| if inlined { |
| decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?; |
| _inner_offset = offset + 8; |
| } else { |
| depth.increment()?; |
| _inner_offset = decoder.out_of_line_offset(member_inline_size)?; |
| } |
| match ordinal { |
| 1 => { |
| #[allow(irrefutable_let_patterns)] |
| if let ExampleUnion::Variant(_) = self { |
| // Do nothing, read the value into the object |
| } else { |
| // Initialize `self` to the right variant |
| *self = ExampleUnion::Variant(fidl::new_empty!(u32, D)); |
| } |
| #[allow(irrefutable_let_patterns)] |
| if let ExampleUnion::Variant(ref mut val) = self { |
| fidl::decode!(u32, D, val, decoder, _inner_offset, depth)?; |
| } else { |
| unreachable!() |
| } |
| } |
| ordinal => panic!("unexpected ordinal {:?}", ordinal), |
| } |
| if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) { |
| return Err(fidl::Error::InvalidNumBytesInEnvelope); |
| } |
| if handles_before != decoder.remaining_handles() + (num_handles as usize) { |
| return Err(fidl::Error::InvalidNumHandlesInEnvelope); |
| } |
| Ok(()) |
| } |
| } |
| } |