| // 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, |
| fidl::{ |
| client::QueryResponseFut, |
| endpoints::{ControlHandle as _, Responder as _}, |
| }, |
| fuchsia_zircon_status as zx_status, |
| futures::future::{self, MaybeDone, TryFutureExt}, |
| }; |
| |
| #[cfg(target_os = "fuchsia")] |
| use fuchsia_zircon as zx; |
| |
| pub type Alias = String; |
| |
| pub const ADDED_AT_HEAD: bool = true; |
| |
| pub const ADDED_AT_NEXT: bool = true; |
| |
| pub const CONST: u32 = 0; |
| |
| bitflags! { |
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| pub struct Bits: u32 { |
| const A = 1; |
| } |
| } |
| |
| impl Bits { |
| #[inline(always)] |
| pub fn from_bits_allow_unknown(bits: u32) -> Self { |
| Self::from_bits_retain(bits) |
| } |
| |
| #[inline(always)] |
| pub fn has_unknown_bits(&self) -> bool { |
| self.get_unknown_bits() != 0 |
| } |
| |
| #[inline(always)] |
| pub fn get_unknown_bits(&self) -> u32 { |
| self.bits() & !Self::all().bits() |
| } |
| } |
| |
| #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| pub enum Enum { |
| A, |
| #[doc(hidden)] |
| __SourceBreaking { |
| unknown_ordinal: u32, |
| }, |
| } |
| |
| /// Pattern that matches an unknown `Enum` member. |
| #[macro_export] |
| macro_rules! EnumUnknown { |
| () => { |
| _ |
| }; |
| } |
| |
| impl Enum { |
| #[inline] |
| pub fn from_primitive(prim: u32) -> Option<Self> { |
| match prim { |
| 1 => Some(Self::A), |
| _ => None, |
| } |
| } |
| |
| #[inline] |
| pub fn from_primitive_allow_unknown(prim: u32) -> Self { |
| match prim { |
| 1 => Self::A, |
| unknown_ordinal => Self::__SourceBreaking { unknown_ordinal }, |
| } |
| } |
| |
| #[inline] |
| pub fn unknown() -> Self { |
| Self::__SourceBreaking { unknown_ordinal: 0xffffffff } |
| } |
| |
| #[inline] |
| pub const fn into_primitive(self) -> u32 { |
| match self { |
| Self::A => 1, |
| Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal, |
| } |
| } |
| |
| #[inline] |
| pub fn is_unknown(&self) -> bool { |
| match self { |
| Self::__SourceBreaking { unknown_ordinal: _ } => true, |
| _ => false, |
| } |
| } |
| } |
| |
| #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| #[repr(C)] |
| pub struct Struct { |
| pub x: u32, |
| } |
| |
| impl fidl::Persistable for Struct {} |
| |
| #[derive(Clone, Debug, Default, PartialEq)] |
| pub struct Table { |
| pub x: Option<u32>, |
| #[doc(hidden)] |
| pub __source_breaking: fidl::marker::SourceBreaking, |
| } |
| |
| impl fidl::Persistable for Table {} |
| |
| #[derive(Clone, Debug)] |
| pub enum Union { |
| X(u32), |
| #[doc(hidden)] |
| __SourceBreaking { |
| unknown_ordinal: u64, |
| }, |
| } |
| |
| /// Pattern that matches an unknown `Union` member. |
| #[macro_export] |
| macro_rules! UnionUnknown { |
| () => { |
| _ |
| }; |
| } |
| |
| // Custom PartialEq so that unknown variants are not equal to themselves. |
| impl PartialEq for Union { |
| fn eq(&self, other: &Self) -> bool { |
| match (self, other) { |
| (Self::X(x), Self::X(y)) => *x == *y, |
| _ => false, |
| } |
| } |
| } |
| |
| impl Union { |
| #[inline] |
| pub fn ordinal(&self) -> u64 { |
| match *self { |
| Self::X(_) => 1, |
| Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal, |
| } |
| } |
| |
| #[inline] |
| pub fn unknown_variant_for_testing() -> Self { |
| Self::__SourceBreaking { unknown_ordinal: 0 } |
| } |
| |
| #[inline] |
| pub fn is_unknown(&self) -> bool { |
| match self { |
| Self::__SourceBreaking { .. } => true, |
| _ => false, |
| } |
| } |
| } |
| |
| impl fidl::Persistable for Union {} |
| |
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| pub struct OtherProtocolMarker; |
| |
| impl fidl::endpoints::ProtocolMarker for OtherProtocolMarker { |
| type Proxy = OtherProtocolProxy; |
| type RequestStream = OtherProtocolRequestStream; |
| |
| #[cfg(target_os = "fuchsia")] |
| type SynchronousProxy = OtherProtocolSynchronousProxy; |
| |
| const DEBUG_NAME: &'static str = "(anonymous) OtherProtocol"; |
| } |
| |
| pub trait OtherProtocolProxyInterface: Send + Sync {} |
| |
| #[derive(Debug)] |
| #[cfg(target_os = "fuchsia")] |
| pub struct OtherProtocolSynchronousProxy { |
| client: fidl::client::sync::Client, |
| } |
| |
| #[cfg(target_os = "fuchsia")] |
| impl fidl::endpoints::SynchronousProxy for OtherProtocolSynchronousProxy { |
| type Proxy = OtherProtocolProxy; |
| type Protocol = OtherProtocolMarker; |
| |
| fn from_channel(inner: fidl::Channel) -> Self { |
| Self::new(inner) |
| } |
| |
| fn into_channel(self) -> fidl::Channel { |
| self.client.into_channel() |
| } |
| |
| fn as_channel(&self) -> &fidl::Channel { |
| self.client.as_channel() |
| } |
| } |
| |
| #[cfg(target_os = "fuchsia")] |
| impl OtherProtocolSynchronousProxy { |
| pub fn new(channel: fidl::Channel) -> Self { |
| let protocol_name = <OtherProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME; |
| Self { client: fidl::client::sync::Client::new(channel, protocol_name) } |
| } |
| |
| pub fn into_channel(self) -> fidl::Channel { |
| self.client.into_channel() |
| } |
| |
| /// Waits until an event arrives and returns it. It is safe for other |
| /// threads to make concurrent requests while waiting for an event. |
| pub fn wait_for_event(&self, deadline: zx::Time) -> Result<OtherProtocolEvent, fidl::Error> { |
| OtherProtocolEvent::decode(self.client.wait_for_event(deadline)?) |
| } |
| } |
| |
| #[derive(Debug, Clone)] |
| pub struct OtherProtocolProxy { |
| client: fidl::client::Client, |
| } |
| |
| impl fidl::endpoints::Proxy for OtherProtocolProxy { |
| type Protocol = OtherProtocolMarker; |
| |
| fn from_channel(inner: fidl::AsyncChannel) -> Self { |
| Self::new(inner) |
| } |
| |
| fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> { |
| self.client.into_channel().map_err(|client| Self { client }) |
| } |
| |
| fn as_channel(&self) -> &::fidl::AsyncChannel { |
| self.client.as_channel() |
| } |
| } |
| |
| impl OtherProtocolProxy { |
| /// Create a new Proxy for test.versions/OtherProtocol. |
| pub fn new(channel: fidl::AsyncChannel) -> Self { |
| let protocol_name = <OtherProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME; |
| Self { client: fidl::client::Client::new(channel, protocol_name) } |
| } |
| |
| /// Get a Stream of events from the remote end of the protocol. |
| /// |
| /// # Panics |
| /// |
| /// Panics if the event stream was already taken. |
| pub fn take_event_stream(&self) -> OtherProtocolEventStream { |
| OtherProtocolEventStream { event_receiver: self.client.take_event_receiver() } |
| } |
| } |
| |
| impl OtherProtocolProxyInterface for OtherProtocolProxy {} |
| |
| pub struct OtherProtocolEventStream { |
| event_receiver: fidl::client::EventReceiver, |
| } |
| |
| impl std::marker::Unpin for OtherProtocolEventStream {} |
| |
| impl futures::stream::FusedStream for OtherProtocolEventStream { |
| fn is_terminated(&self) -> bool { |
| self.event_receiver.is_terminated() |
| } |
| } |
| |
| impl futures::Stream for OtherProtocolEventStream { |
| type Item = Result<OtherProtocolEvent, fidl::Error>; |
| |
| fn poll_next( |
| mut self: std::pin::Pin<&mut Self>, |
| cx: &mut std::task::Context<'_>, |
| ) -> std::task::Poll<Option<Self::Item>> { |
| match futures::ready!(futures::stream::StreamExt::poll_next_unpin( |
| &mut self.event_receiver, |
| cx |
| )?) { |
| Some(buf) => std::task::Poll::Ready(Some(OtherProtocolEvent::decode(buf))), |
| None => std::task::Poll::Ready(None), |
| } |
| } |
| } |
| |
| #[derive(Debug)] |
| pub enum OtherProtocolEvent {} |
| |
| impl OtherProtocolEvent { |
| /// Decodes a message buffer as a [`OtherProtocolEvent`]. |
| fn decode(mut buf: fidl::MessageBufEtc) -> Result<OtherProtocolEvent, fidl::Error> { |
| let (bytes, _handles) = buf.split_mut(); |
| let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; |
| debug_assert_eq!(tx_header.tx_id, 0); |
| match tx_header.ordinal { |
| _ => Err(fidl::Error::UnknownOrdinal { |
| ordinal: tx_header.ordinal, |
| protocol_name: <OtherProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME, |
| }), |
| } |
| } |
| } |
| |
| /// A Stream of incoming requests for test.versions/OtherProtocol. |
| pub struct OtherProtocolRequestStream { |
| inner: std::sync::Arc<fidl::ServeInner>, |
| is_terminated: bool, |
| } |
| |
| impl std::marker::Unpin for OtherProtocolRequestStream {} |
| |
| impl futures::stream::FusedStream for OtherProtocolRequestStream { |
| fn is_terminated(&self) -> bool { |
| self.is_terminated |
| } |
| } |
| |
| impl fidl::endpoints::RequestStream for OtherProtocolRequestStream { |
| type Protocol = OtherProtocolMarker; |
| type ControlHandle = OtherProtocolControlHandle; |
| |
| fn from_channel(channel: fidl::AsyncChannel) -> Self { |
| Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false } |
| } |
| |
| fn control_handle(&self) -> Self::ControlHandle { |
| OtherProtocolControlHandle { inner: self.inner.clone() } |
| } |
| |
| fn into_inner(self) -> (::std::sync::Arc<fidl::ServeInner>, bool) { |
| (self.inner, self.is_terminated) |
| } |
| |
| fn from_inner(inner: std::sync::Arc<fidl::ServeInner>, is_terminated: bool) -> Self { |
| Self { inner, is_terminated } |
| } |
| } |
| |
| impl futures::Stream for OtherProtocolRequestStream { |
| type Item = Result<OtherProtocolRequest, fidl::Error>; |
| |
| fn poll_next( |
| mut self: std::pin::Pin<&mut Self>, |
| cx: &mut std::task::Context<'_>, |
| ) -> std::task::Poll<Option<Self::Item>> { |
| let this = &mut *self; |
| if this.inner.check_shutdown(cx) { |
| this.is_terminated = true; |
| return std::task::Poll::Ready(None); |
| } |
| if this.is_terminated { |
| panic!("polled OtherProtocolRequestStream after completion"); |
| } |
| fidl::encoding::with_tls_decode_buf(|bytes, handles| { |
| match this.inner.channel().read_etc(cx, bytes, handles) { |
| std::task::Poll::Ready(Ok(())) => {} |
| std::task::Poll::Pending => return std::task::Poll::Pending, |
| std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => { |
| this.is_terminated = true; |
| return std::task::Poll::Ready(None); |
| } |
| std::task::Poll::Ready(Err(e)) => { |
| return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(e)))) |
| } |
| } |
| |
| // A message has been received from the channel |
| let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; |
| |
| std::task::Poll::Ready(Some(match header.ordinal { |
| _ => Err(fidl::Error::UnknownOrdinal { |
| ordinal: header.ordinal, |
| protocol_name: |
| <OtherProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME, |
| }), |
| })) |
| }) |
| } |
| } |
| |
| #[derive(Debug)] |
| pub enum OtherProtocolRequest {} |
| |
| impl OtherProtocolRequest { |
| /// Name of the method defined in FIDL |
| pub fn method_name(&self) -> &'static str { |
| match *self {} |
| } |
| } |
| |
| #[derive(Debug, Clone)] |
| pub struct OtherProtocolControlHandle { |
| inner: std::sync::Arc<fidl::ServeInner>, |
| } |
| |
| impl fidl::endpoints::ControlHandle for OtherProtocolControlHandle { |
| fn shutdown(&self) { |
| self.inner.shutdown() |
| } |
| |
| fn shutdown_with_epitaph(&self, status: zx_status::Status) { |
| self.inner.shutdown_with_epitaph(status) |
| } |
| |
| fn is_closed(&self) -> bool { |
| self.inner.channel().is_closed() |
| } |
| |
| fn on_closed(&self) -> fidl::OnSignalsRef<'_> { |
| self.inner.channel().on_closed() |
| } |
| } |
| |
| impl OtherProtocolControlHandle {} |
| |
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| pub struct ProtocolMarker; |
| |
| impl fidl::endpoints::ProtocolMarker for ProtocolMarker { |
| type Proxy = ProtocolProxy; |
| type RequestStream = ProtocolRequestStream; |
| |
| #[cfg(target_os = "fuchsia")] |
| type SynchronousProxy = ProtocolSynchronousProxy; |
| |
| const DEBUG_NAME: &'static str = "(anonymous) Protocol"; |
| } |
| |
| pub trait ProtocolProxyInterface: Send + Sync { |
| fn r#foo(&self) -> Result<(), fidl::Error>; |
| } |
| |
| #[derive(Debug)] |
| #[cfg(target_os = "fuchsia")] |
| pub struct ProtocolSynchronousProxy { |
| client: fidl::client::sync::Client, |
| } |
| |
| #[cfg(target_os = "fuchsia")] |
| impl fidl::endpoints::SynchronousProxy for ProtocolSynchronousProxy { |
| type Proxy = ProtocolProxy; |
| type Protocol = ProtocolMarker; |
| |
| fn from_channel(inner: fidl::Channel) -> Self { |
| Self::new(inner) |
| } |
| |
| fn into_channel(self) -> fidl::Channel { |
| self.client.into_channel() |
| } |
| |
| fn as_channel(&self) -> &fidl::Channel { |
| self.client.as_channel() |
| } |
| } |
| |
| #[cfg(target_os = "fuchsia")] |
| impl ProtocolSynchronousProxy { |
| pub fn new(channel: fidl::Channel) -> Self { |
| let protocol_name = <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME; |
| Self { client: fidl::client::sync::Client::new(channel, protocol_name) } |
| } |
| |
| pub fn into_channel(self) -> fidl::Channel { |
| self.client.into_channel() |
| } |
| |
| /// Waits until an event arrives and returns it. It is safe for other |
| /// threads to make concurrent requests while waiting for an event. |
| pub fn wait_for_event(&self, deadline: zx::Time) -> Result<ProtocolEvent, fidl::Error> { |
| ProtocolEvent::decode(self.client.wait_for_event(deadline)?) |
| } |
| |
| pub fn r#foo(&self) -> Result<(), fidl::Error> { |
| self.client.send::<fidl::encoding::EmptyPayload>( |
| (), |
| 0x567a8096af6e6139, |
| fidl::encoding::DynamicFlags::empty(), |
| ) |
| } |
| } |
| |
| #[derive(Debug, Clone)] |
| pub struct ProtocolProxy { |
| client: fidl::client::Client, |
| } |
| |
| impl fidl::endpoints::Proxy for ProtocolProxy { |
| type Protocol = ProtocolMarker; |
| |
| fn from_channel(inner: fidl::AsyncChannel) -> Self { |
| Self::new(inner) |
| } |
| |
| fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> { |
| self.client.into_channel().map_err(|client| Self { client }) |
| } |
| |
| fn as_channel(&self) -> &::fidl::AsyncChannel { |
| self.client.as_channel() |
| } |
| } |
| |
| impl ProtocolProxy { |
| /// Create a new Proxy for test.versions/Protocol. |
| pub fn new(channel: fidl::AsyncChannel) -> Self { |
| let protocol_name = <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME; |
| Self { client: fidl::client::Client::new(channel, protocol_name) } |
| } |
| |
| /// Get a Stream of events from the remote end of the protocol. |
| /// |
| /// # Panics |
| /// |
| /// Panics if the event stream was already taken. |
| pub fn take_event_stream(&self) -> ProtocolEventStream { |
| ProtocolEventStream { event_receiver: self.client.take_event_receiver() } |
| } |
| |
| pub fn r#foo(&self) -> Result<(), fidl::Error> { |
| ProtocolProxyInterface::r#foo(self) |
| } |
| } |
| |
| impl ProtocolProxyInterface for ProtocolProxy { |
| fn r#foo(&self) -> Result<(), fidl::Error> { |
| self.client.send::<fidl::encoding::EmptyPayload>( |
| (), |
| 0x567a8096af6e6139, |
| fidl::encoding::DynamicFlags::empty(), |
| ) |
| } |
| } |
| |
| pub struct ProtocolEventStream { |
| event_receiver: fidl::client::EventReceiver, |
| } |
| |
| impl std::marker::Unpin for ProtocolEventStream {} |
| |
| impl futures::stream::FusedStream for ProtocolEventStream { |
| fn is_terminated(&self) -> bool { |
| self.event_receiver.is_terminated() |
| } |
| } |
| |
| impl futures::Stream for ProtocolEventStream { |
| type Item = Result<ProtocolEvent, fidl::Error>; |
| |
| fn poll_next( |
| mut self: std::pin::Pin<&mut Self>, |
| cx: &mut std::task::Context<'_>, |
| ) -> std::task::Poll<Option<Self::Item>> { |
| match futures::ready!(futures::stream::StreamExt::poll_next_unpin( |
| &mut self.event_receiver, |
| cx |
| )?) { |
| Some(buf) => std::task::Poll::Ready(Some(ProtocolEvent::decode(buf))), |
| None => std::task::Poll::Ready(None), |
| } |
| } |
| } |
| |
| #[derive(Debug)] |
| pub enum ProtocolEvent {} |
| |
| impl ProtocolEvent { |
| /// Decodes a message buffer as a [`ProtocolEvent`]. |
| fn decode(mut buf: fidl::MessageBufEtc) -> Result<ProtocolEvent, fidl::Error> { |
| let (bytes, _handles) = buf.split_mut(); |
| let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; |
| debug_assert_eq!(tx_header.tx_id, 0); |
| match tx_header.ordinal { |
| _ => Err(fidl::Error::UnknownOrdinal { |
| ordinal: tx_header.ordinal, |
| protocol_name: <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME, |
| }), |
| } |
| } |
| } |
| |
| /// A Stream of incoming requests for test.versions/Protocol. |
| pub struct ProtocolRequestStream { |
| inner: std::sync::Arc<fidl::ServeInner>, |
| is_terminated: bool, |
| } |
| |
| impl std::marker::Unpin for ProtocolRequestStream {} |
| |
| impl futures::stream::FusedStream for ProtocolRequestStream { |
| fn is_terminated(&self) -> bool { |
| self.is_terminated |
| } |
| } |
| |
| impl fidl::endpoints::RequestStream for ProtocolRequestStream { |
| type Protocol = ProtocolMarker; |
| type ControlHandle = ProtocolControlHandle; |
| |
| fn from_channel(channel: fidl::AsyncChannel) -> Self { |
| Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false } |
| } |
| |
| fn control_handle(&self) -> Self::ControlHandle { |
| ProtocolControlHandle { inner: self.inner.clone() } |
| } |
| |
| fn into_inner(self) -> (::std::sync::Arc<fidl::ServeInner>, bool) { |
| (self.inner, self.is_terminated) |
| } |
| |
| fn from_inner(inner: std::sync::Arc<fidl::ServeInner>, is_terminated: bool) -> Self { |
| Self { inner, is_terminated } |
| } |
| } |
| |
| impl futures::Stream for ProtocolRequestStream { |
| type Item = Result<ProtocolRequest, fidl::Error>; |
| |
| fn poll_next( |
| mut self: std::pin::Pin<&mut Self>, |
| cx: &mut std::task::Context<'_>, |
| ) -> std::task::Poll<Option<Self::Item>> { |
| let this = &mut *self; |
| if this.inner.check_shutdown(cx) { |
| this.is_terminated = true; |
| return std::task::Poll::Ready(None); |
| } |
| if this.is_terminated { |
| panic!("polled ProtocolRequestStream after completion"); |
| } |
| fidl::encoding::with_tls_decode_buf(|bytes, handles| { |
| match this.inner.channel().read_etc(cx, bytes, handles) { |
| std::task::Poll::Ready(Ok(())) => {} |
| std::task::Poll::Pending => return std::task::Poll::Pending, |
| std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => { |
| this.is_terminated = true; |
| return std::task::Poll::Ready(None); |
| } |
| std::task::Poll::Ready(Err(e)) => { |
| return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(e)))) |
| } |
| } |
| |
| // A message has been received from the channel |
| let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; |
| |
| std::task::Poll::Ready(Some(match header.ordinal { |
| 0x567a8096af6e6139 => { |
| header.validate_request_tx_id(fidl::MethodType::OneWay)?; |
| let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload); |
| fidl::encoding::Decoder::decode_into::<fidl::encoding::EmptyPayload>( |
| &header, |
| _body_bytes, |
| handles, |
| &mut req, |
| )?; |
| let control_handle = ProtocolControlHandle { inner: this.inner.clone() }; |
| Ok(ProtocolRequest::Foo { control_handle }) |
| } |
| _ => Err(fidl::Error::UnknownOrdinal { |
| ordinal: header.ordinal, |
| protocol_name: <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME, |
| }), |
| })) |
| }) |
| } |
| } |
| |
| #[derive(Debug)] |
| pub enum ProtocolRequest { |
| Foo { control_handle: ProtocolControlHandle }, |
| } |
| |
| impl ProtocolRequest { |
| #[allow(irrefutable_let_patterns)] |
| pub fn into_foo(self) -> Option<(ProtocolControlHandle)> { |
| if let ProtocolRequest::Foo { control_handle } = self { |
| Some((control_handle)) |
| } else { |
| None |
| } |
| } |
| |
| /// Name of the method defined in FIDL |
| pub fn method_name(&self) -> &'static str { |
| match *self { |
| ProtocolRequest::Foo { .. } => "foo", |
| } |
| } |
| } |
| |
| #[derive(Debug, Clone)] |
| pub struct ProtocolControlHandle { |
| inner: std::sync::Arc<fidl::ServeInner>, |
| } |
| |
| impl fidl::endpoints::ControlHandle for ProtocolControlHandle { |
| fn shutdown(&self) { |
| self.inner.shutdown() |
| } |
| |
| fn shutdown_with_epitaph(&self, status: zx_status::Status) { |
| self.inner.shutdown_with_epitaph(status) |
| } |
| |
| fn is_closed(&self) -> bool { |
| self.inner.channel().is_closed() |
| } |
| |
| fn on_closed(&self) -> fidl::OnSignalsRef<'_> { |
| self.inner.channel().on_closed() |
| } |
| } |
| |
| impl ProtocolControlHandle {} |
| |
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| pub struct ServiceMarker; |
| |
| #[cfg(target_os = "fuchsia")] |
| impl fidl::endpoints::ServiceMarker for ServiceMarker { |
| type Proxy = ServiceProxy; |
| type Request = ServiceRequest; |
| const SERVICE_NAME: &'static str = "test.versions.Service"; |
| } |
| |
| /// A request for one of the member protocols of Service. |
| /// |
| #[cfg(target_os = "fuchsia")] |
| pub enum ServiceRequest { |
| P(ProtocolRequestStream), |
| } |
| |
| #[cfg(target_os = "fuchsia")] |
| impl fidl::endpoints::ServiceRequest for ServiceRequest { |
| type Service = ServiceMarker; |
| |
| fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self { |
| match name { |
| "p" => Self::P( |
| <ProtocolRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel), |
| ), |
| _ => panic!("no such member protocol name for service Service"), |
| } |
| } |
| |
| fn member_names() -> &'static [&'static str] { |
| &["p"] |
| } |
| } |
| #[cfg(target_os = "fuchsia")] |
| pub struct ServiceProxy(Box<dyn fidl::endpoints::MemberOpener>); |
| |
| #[cfg(target_os = "fuchsia")] |
| impl fidl::endpoints::ServiceProxy for ServiceProxy { |
| type Service = ServiceMarker; |
| |
| fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self { |
| Self(opener) |
| } |
| } |
| |
| #[cfg(target_os = "fuchsia")] |
| impl ServiceProxy { |
| pub fn connect_to_p(&self) -> Result<ProtocolProxy, fidl::Error> { |
| let (proxy, server_end) = fidl::endpoints::create_proxy::<ProtocolMarker>()?; |
| self.connect_channel_to_p(server_end)?; |
| Ok(proxy) |
| } |
| |
| /// Like `connect_to_p`, but accepts a server end. |
| pub fn connect_channel_to_p( |
| &self, |
| server_end: fidl::endpoints::ServerEnd<ProtocolMarker>, |
| ) -> Result<(), fidl::Error> { |
| self.0.open_member("p", server_end.into_channel()) |
| } |
| } |
| |
| 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<'a>( |
| value: &'a <Self as fidl::encoding::TypeMarker>::Owned, |
| ) -> Self::Borrowed<'a> { |
| *value |
| } |
| } |
| |
| unsafe impl fidl::encoding::Encode<Self> for Bits { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Self>(offset); |
| encoder.write_num(self.bits(), offset); |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::Decode<Self> for Bits { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::empty() |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_>, |
| 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_allow_unknown(prim); |
| 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 { |
| false |
| } |
| |
| #[inline(always)] |
| fn decode_is_copy() -> bool { |
| false |
| } |
| } |
| |
| impl fidl::encoding::ValueTypeMarker for Enum { |
| type Borrowed<'a> = Self; |
| #[inline(always)] |
| fn borrow<'a>( |
| value: &'a <Self as fidl::encoding::TypeMarker>::Owned, |
| ) -> Self::Borrowed<'a> { |
| *value |
| } |
| } |
| |
| unsafe impl fidl::encoding::Encode<Self> for Enum { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Self>(offset); |
| encoder.write_num(self.into_primitive(), offset); |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::Decode<Self> for Enum { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::unknown() |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_>, |
| 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_allow_unknown(prim); |
| Ok(()) |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for Struct { |
| 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 |
| } |
| } |
| impl fidl::encoding::ValueTypeMarker for Struct { |
| type Borrowed<'a> = &'a Self; |
| fn borrow<'a>( |
| value: &'a <Self as fidl::encoding::TypeMarker>::Owned, |
| ) -> Self::Borrowed<'a> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::Encode<Struct> for &Struct { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Struct>(offset); |
| unsafe { |
| // Copy the object into the buffer. |
| let buf_ptr = encoder.buf.as_mut_ptr().add(offset); |
| (buf_ptr as *mut Struct).write_unaligned((self as *const Struct).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<T0: fidl::encoding::Encode<u32>> fidl::encoding::Encode<Struct> for (T0,) { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_>, |
| 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. |
| // Write the fields. |
| self.0.encode(encoder, offset + 0, depth)?; |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::Decode<Self> for Struct { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self { x: fidl::new_empty!(u32) } |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_>, |
| 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 Table { |
| #[inline(always)] |
| fn max_ordinal_present(&self) -> u64 { |
| if let Some(_) = self.x { |
| return 1; |
| } |
| 0 |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for Table { |
| 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 |
| } |
| } |
| impl fidl::encoding::ValueTypeMarker for Table { |
| type Borrowed<'a> = &'a Self; |
| fn borrow<'a>( |
| value: &'a <Self as fidl::encoding::TypeMarker>::Owned, |
| ) -> Self::Borrowed<'a> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::Encode<Table> for &Table { |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_>, |
| offset: usize, |
| mut depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Table>(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>( |
| self.x.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow), |
| encoder, |
| offset + cur_offset, |
| depth, |
| )?; |
| |
| _prev_end_offset = cur_offset + envelope_size; |
| |
| Ok(()) |
| } |
| } |
| |
| impl fidl::encoding::Decode<Self> for Table { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::default() |
| } |
| |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_>, |
| 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.x.get_or_insert_with(|| fidl::new_empty!(u32)); |
| fidl::decode!(u32, 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(()) |
| } |
| } |
| |
| unsafe impl fidl::encoding::TypeMarker for Union { |
| 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 |
| } |
| } |
| impl fidl::encoding::ValueTypeMarker for Union { |
| type Borrowed<'a> = &'a Self; |
| fn borrow<'a>( |
| value: &'a <Self as fidl::encoding::TypeMarker>::Owned, |
| ) -> Self::Borrowed<'a> { |
| value |
| } |
| } |
| |
| unsafe impl fidl::encoding::Encode<Union> for &Union { |
| #[inline] |
| unsafe fn encode( |
| self, |
| encoder: &mut fidl::encoding::Encoder<'_>, |
| offset: usize, |
| _depth: fidl::encoding::Depth, |
| ) -> fidl::Result<()> { |
| encoder.debug_check_bounds::<Union>(offset); |
| encoder.write_num::<u64>(self.ordinal(), offset); |
| match self { |
| Union::X(ref val) => fidl::encoding::encode_in_envelope::<u32>( |
| <u32 as fidl::encoding::ValueTypeMarker>::borrow(val), |
| encoder, |
| offset + 8, |
| _depth, |
| ), |
| Union::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag), |
| } |
| } |
| } |
| |
| impl fidl::encoding::Decode<Self> for Union { |
| #[inline(always)] |
| fn new_empty() -> Self { |
| Self::__SourceBreaking { unknown_ordinal: 0 } |
| } |
| |
| #[inline] |
| unsafe fn decode( |
| &mut self, |
| decoder: &mut fidl::encoding::Decoder<'_>, |
| 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), |
| 0 => return Err(fidl::Error::UnknownUnionTag), |
| _ => num_bytes as usize, |
| }; |
| |
| 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 Union::X(_) = self { |
| // Do nothing, read the value into the object |
| } else { |
| // Initialize `self` to the right variant |
| *self = Union::X(fidl::new_empty!(u32)); |
| } |
| #[allow(irrefutable_let_patterns)] |
| if let Union::X(ref mut val) = self { |
| fidl::decode!(u32, val, decoder, _inner_offset, depth)?; |
| } else { |
| unreachable!() |
| } |
| } |
| #[allow(deprecated)] |
| ordinal => { |
| for _ in 0..num_handles { |
| decoder.drop_next_handle()?; |
| } |
| *self = Union::__SourceBreaking { unknown_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(()) |
| } |
| } |
| } |