Created
July 14, 2020 15:18
-
-
Save bprosnitz/a59001dd6e03882cc0e37c0a6e6bcc70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | |
pub struct ByteVectorEventProtocolMarker; | |
impl fidl::endpoints::ServiceMarker for ByteVectorEventProtocolMarker { | |
type Proxy = ByteVectorEventProtocolProxy; | |
type RequestStream = ByteVectorEventProtocolRequestStream; | |
const DEBUG_NAME: &'static str = "(anonymous) ByteVectorEventProtocol"; | |
} | |
pub trait ByteVectorEventProtocolProxyInterface: Send + Sync { | |
type Send_ResponseFut: std::future::Future<Output = Result<(ByteVector), fidl::Error>> + Send; | |
} | |
#[derive(Debug)] | |
#[cfg(target_os = "fuchsia")] | |
pub struct ByteVectorEventProtocolSynchronousProxy { | |
client: fidl::client::sync::Client, | |
} | |
#[cfg(target_os = "fuchsia")] | |
impl ByteVectorEventProtocolSynchronousProxy { | |
pub fn new(channel: ::fidl::Channel) -> Self { | |
Self { client: fidl::client::sync::Client::new(channel) } | |
} | |
pub fn into_channel(self) -> ::fidl::Channel { | |
self.client.into_channel() | |
} | |
} | |
#[derive(Debug, Clone)] | |
pub struct ByteVectorEventProtocolProxy { | |
client: fidl::client::Client, | |
} | |
impl fidl::endpoints::Proxy for ByteVectorEventProtocolProxy { | |
type Service = ByteVectorEventProtocolMarker; | |
fn from_channel(inner: ::fidl::AsyncChannel) -> Self { | |
Self::new(inner) | |
} | |
} | |
impl ::std::ops::Deref for ByteVectorEventProtocolProxy { | |
type Target = fidl::client::Client; | |
fn deref(&self) -> &Self::Target { | |
&self.client | |
} | |
} | |
impl ByteVectorEventProtocolProxy { | |
/// Create a new Proxy for ByteVectorEventProtocol | |
pub fn new(channel: ::fidl::AsyncChannel) -> Self { | |
Self { client: fidl::client::Client::new(channel) } | |
} | |
/// Attempt to convert the Proxy back into a channel. | |
/// | |
/// This will only succeed if there are no active clones of this Proxy | |
/// and no currently-alive EventStream or response futures that came from | |
/// this Proxy. | |
pub fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> { | |
self.client.into_channel().map_err(|client| Self { client }) | |
} | |
/// Get a Stream of events from the remote end of the ByteVectorEventProtocol protocol | |
/// | |
/// # Panics | |
/// | |
/// Panics if the event stream was already taken. | |
pub fn take_event_stream(&self) -> ByteVectorEventProtocolEventStream { | |
ByteVectorEventProtocolEventStream { event_receiver: self.client.take_event_receiver() } | |
} | |
} | |
impl ByteVectorEventProtocolProxyInterface for ByteVectorEventProtocolProxy { | |
type Send_ResponseFut = fidl::client::QueryResponseFut<(ByteVector)>; | |
} | |
pub struct ByteVectorEventProtocolEventStream { | |
event_receiver: fidl::client::EventReceiver, | |
} | |
impl ::std::marker::Unpin for ByteVectorEventProtocolEventStream {} | |
impl futures::stream::FusedStream for ByteVectorEventProtocolEventStream { | |
fn is_terminated(&self) -> bool { | |
self.event_receiver.is_terminated() | |
} | |
} | |
impl futures::Stream for ByteVectorEventProtocolEventStream { | |
type Item = Result<ByteVectorEventProtocolEvent, fidl::Error>; | |
fn poll_next( | |
mut self: ::std::pin::Pin<&mut Self>, | |
cx: &mut std::task::Context<'_>, | |
) -> std::task::Poll<Option<Self::Item>> { | |
let mut buf = match futures::ready!(futures::stream::StreamExt::poll_next_unpin( | |
&mut self.event_receiver, | |
cx | |
)?) { | |
Some(buf) => buf, | |
None => return std::task::Poll::Ready(None), | |
}; | |
let (bytes, _handles) = buf.split_mut(); | |
let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; | |
std::task::Poll::Ready(Some(match tx_header.ordinal() { | |
0x32c632794131eaf4 => { | |
let mut out_tuple: (ByteVector) = fidl::encoding::Decodable::new_empty(); | |
fidl::encoding::Decoder::decode_into( | |
&tx_header, | |
_body_bytes, | |
_handles, | |
&mut out_tuple, | |
)?; | |
Ok((ByteVectorEventProtocolEvent::Send_ { val: out_tuple })) | |
} | |
_ => Err(fidl::Error::UnknownOrdinal { | |
ordinal: tx_header.ordinal(), | |
service_name: | |
<ByteVectorEventProtocolMarker as fidl::endpoints::ServiceMarker>::DEBUG_NAME, | |
}), | |
})) | |
} | |
} | |
#[derive(Debug)] | |
pub enum ByteVectorEventProtocolEvent { | |
Send_ { val: ByteVector }, | |
} | |
impl ByteVectorEventProtocolEvent { | |
#[allow(irrefutable_let_patterns)] | |
pub fn into_send_(self) -> Option<(ByteVector)> { | |
if let ByteVectorEventProtocolEvent::Send_ { val } = self { | |
Some((val)) | |
} else { | |
None | |
} | |
} | |
} | |
/// A type which can be used to send responses and events into a borrowed channel. | |
/// | |
/// Note: this should only be used when the channel must be temporarily | |
/// borrowed. For a typical sending of events, use the send_ methods | |
/// on the ControlHandle types, which can be acquired through a | |
/// RequestStream or Responder type. | |
#[deprecated(note = "Use ByteVectorEventProtocolRequestStream / Responder instead")] | |
pub struct ByteVectorEventProtocolServerSender<'a> { | |
// Some protocols don't define events which would render this channel unused. | |
#[allow(unused)] | |
channel: &'a ::fidl::Channel, | |
} | |
impl<'a> ByteVectorEventProtocolServerSender<'a> { | |
pub fn new(channel: &'a ::fidl::Channel) -> Self { | |
Self { channel } | |
} | |
pub fn send_send_(&self, mut val: &mut ByteVector) -> Result<(), fidl::Error> { | |
::fidl::encoding::with_tls_coding_bufs(|bytes, handles| { | |
ByteVectorEventProtocolEncoder::encode_send__response(bytes, handles, val)?; | |
self.channel.write(&*bytes, &mut *handles).map_err(fidl::Error::ServerResponseWrite)?; | |
Ok(()) | |
}) | |
} | |
} | |
/// A Stream of incoming requests for ByteVectorEventProtocol | |
pub struct ByteVectorEventProtocolRequestStream { | |
inner: ::std::sync::Arc<fidl::ServeInner>, | |
is_terminated: bool, | |
} | |
impl ::std::marker::Unpin for ByteVectorEventProtocolRequestStream {} | |
impl futures::stream::FusedStream for ByteVectorEventProtocolRequestStream { | |
fn is_terminated(&self) -> bool { | |
self.is_terminated | |
} | |
} | |
impl fidl::endpoints::RequestStream for ByteVectorEventProtocolRequestStream { | |
type Service = ByteVectorEventProtocolMarker; | |
/// Consume a channel to make a ByteVectorEventProtocolRequestStream | |
fn from_channel(channel: ::fidl::AsyncChannel) -> Self { | |
Self { inner: ::std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false } | |
} | |
/// ControlHandle for the remote connection | |
type ControlHandle = ByteVectorEventProtocolControlHandle; | |
/// ControlHandle for the remote connection | |
fn control_handle(&self) -> Self::ControlHandle { | |
ByteVectorEventProtocolControlHandle { 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 ByteVectorEventProtocolRequestStream { | |
type Item = Result<ByteVectorEventProtocolRequest, 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.poll_shutdown(cx) { | |
this.is_terminated = true; | |
return std::task::Poll::Ready(None); | |
} | |
if this.is_terminated { | |
panic!("polled ByteVectorEventProtocolRequestStream after completion"); | |
} | |
::fidl::encoding::with_tls_coding_bufs(|bytes, handles| { | |
match this.inner.channel().read(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)?; | |
if !header.is_compatible() { | |
return std::task::Poll::Ready(Some(Err(fidl::Error::IncompatibleMagicNumber( | |
header.magic_number(), | |
)))); | |
} | |
std::task::Poll::Ready(Some(match header.ordinal() { | |
_ => Err(fidl::Error::UnknownOrdinal { | |
ordinal: header.ordinal(), | |
service_name: <ByteVectorEventProtocolMarker as fidl::endpoints::ServiceMarker>::DEBUG_NAME, | |
}), | |
})) | |
}) | |
} | |
} | |
/// Represents a single request. | |
/// RequestMessages should only be used for manual deserialization when higher level | |
/// structs such as RequestStream cannot be used. One usually would only encounter | |
/// such scenarios when working with legacy FIDL code (prior to FIDL generated client/server bindings). | |
#[derive(Debug)] | |
#[deprecated(note = "Use ByteVectorEventProtocolRequest instead")] | |
pub enum ByteVectorEventProtocolRequestMessage {} | |
impl ByteVectorEventProtocolRequestMessage { | |
pub fn decode( | |
bytes: &[u8], | |
_handles: &mut [fidl::Handle], | |
) -> Result<ByteVectorEventProtocolRequestMessage, fidl::Error> { | |
let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; | |
match header.ordinal() { | |
_ => Err(fidl::Error::UnknownOrdinal { | |
ordinal: header.ordinal(), | |
service_name: | |
<ByteVectorEventProtocolMarker as fidl::endpoints::ServiceMarker>::DEBUG_NAME, | |
}), | |
} | |
} | |
} | |
#[derive(Debug)] | |
pub enum ByteVectorEventProtocolRequest {} | |
impl ByteVectorEventProtocolRequest { | |
/// Name of the method defined in FIDL | |
pub fn method_name(&self) -> &'static str { | |
match *self {} | |
} | |
} | |
pub struct ByteVectorEventProtocolEncoder; | |
impl ByteVectorEventProtocolEncoder { | |
pub fn encode_send__response<'a>( | |
out_bytes: &'a mut Vec<u8>, | |
out_handles: &'a mut Vec<fidl::Handle>, | |
mut in_val: &mut ByteVector, | |
) -> Result<(), fidl::Error> { | |
let header = fidl::encoding::TransactionHeader::new(0, 0x32c632794131eaf4); | |
let mut body = (in_val,); | |
let mut msg = fidl::encoding::TransactionMessage { header, body: &mut body }; | |
fidl::encoding::Encoder::encode(out_bytes, out_handles, &mut msg)?; | |
Ok(()) | |
} | |
} | |
#[derive(Debug, Clone)] | |
pub struct ByteVectorEventProtocolControlHandle { | |
inner: ::std::sync::Arc<fidl::ServeInner>, | |
} | |
impl ::std::ops::Deref for ByteVectorEventProtocolControlHandle { | |
type Target = ::std::sync::Arc<fidl::ServeInner>; | |
fn deref(&self) -> &Self::Target { | |
&self.inner | |
} | |
} | |
impl ByteVectorEventProtocolControlHandle { | |
pub fn shutdown(&self) { | |
self.inner.shutdown() | |
} | |
pub fn shutdown_with_epitaph(&self, status: zx_status::Status) { | |
self.inner.shutdown_with_epitaph(status) | |
} | |
pub fn send_send_(&self, mut val: &mut ByteVector) -> Result<(), fidl::Error> { | |
let header = fidl::encoding::TransactionHeader::new(0, 0x32c632794131eaf4); | |
let mut response = (val); | |
let mut msg = fidl::encoding::TransactionMessage { header, body: &mut response }; | |
::fidl::encoding::with_tls_encoded(&mut msg, |bytes, handles| { | |
self.inner | |
.channel() | |
.write(&*bytes, &mut *handles) | |
.map_err(fidl::Error::ServerResponseWrite) | |
})?; | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment