1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_test_echo__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct EchoMarker;
16
17impl fidl::endpoints::ProtocolMarker for EchoMarker {
18 type Proxy = EchoProxy;
19 type RequestStream = EchoRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = EchoSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "test.echo.Echo";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for EchoMarker {}
26
27pub trait EchoProxyInterface: Send + Sync {
28 type EchoStringResponseFut: std::future::Future<Output = Result<Option<String>, fidl::Error>>
29 + Send;
30 fn r#echo_string(&self, value: Option<&str>) -> Self::EchoStringResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct EchoSynchronousProxy {
35 client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for EchoSynchronousProxy {
40 type Proxy = EchoProxy;
41 type Protocol = EchoMarker;
42
43 fn from_channel(inner: fidl::Channel) -> Self {
44 Self::new(inner)
45 }
46
47 fn into_channel(self) -> fidl::Channel {
48 self.client.into_channel()
49 }
50
51 fn as_channel(&self) -> &fidl::Channel {
52 self.client.as_channel()
53 }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl EchoSynchronousProxy {
58 pub fn new(channel: fidl::Channel) -> Self {
59 let protocol_name = <EchoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
60 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
61 }
62
63 pub fn into_channel(self) -> fidl::Channel {
64 self.client.into_channel()
65 }
66
67 pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<EchoEvent, fidl::Error> {
70 EchoEvent::decode(self.client.wait_for_event(deadline)?)
71 }
72
73 pub fn r#echo_string(
74 &self,
75 mut value: Option<&str>,
76 ___deadline: zx::MonotonicInstant,
77 ) -> Result<Option<String>, fidl::Error> {
78 let _response = self.client.send_query::<EchoEchoStringRequest, EchoEchoStringResponse>(
79 (value,),
80 0x1e16cc1b194790f6,
81 fidl::encoding::DynamicFlags::empty(),
82 ___deadline,
83 )?;
84 Ok(_response.response)
85 }
86}
87
88#[cfg(target_os = "fuchsia")]
89impl From<EchoSynchronousProxy> for zx::Handle {
90 fn from(value: EchoSynchronousProxy) -> Self {
91 value.into_channel().into()
92 }
93}
94
95#[cfg(target_os = "fuchsia")]
96impl From<fidl::Channel> for EchoSynchronousProxy {
97 fn from(value: fidl::Channel) -> Self {
98 Self::new(value)
99 }
100}
101
102#[cfg(target_os = "fuchsia")]
103impl fidl::endpoints::FromClient for EchoSynchronousProxy {
104 type Protocol = EchoMarker;
105
106 fn from_client(value: fidl::endpoints::ClientEnd<EchoMarker>) -> Self {
107 Self::new(value.into_channel())
108 }
109}
110
111#[derive(Debug, Clone)]
112pub struct EchoProxy {
113 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
114}
115
116impl fidl::endpoints::Proxy for EchoProxy {
117 type Protocol = EchoMarker;
118
119 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
120 Self::new(inner)
121 }
122
123 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
124 self.client.into_channel().map_err(|client| Self { client })
125 }
126
127 fn as_channel(&self) -> &::fidl::AsyncChannel {
128 self.client.as_channel()
129 }
130}
131
132impl EchoProxy {
133 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
135 let protocol_name = <EchoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
136 Self { client: fidl::client::Client::new(channel, protocol_name) }
137 }
138
139 pub fn take_event_stream(&self) -> EchoEventStream {
145 EchoEventStream { event_receiver: self.client.take_event_receiver() }
146 }
147
148 pub fn r#echo_string(
149 &self,
150 mut value: Option<&str>,
151 ) -> fidl::client::QueryResponseFut<Option<String>, fidl::encoding::DefaultFuchsiaResourceDialect>
152 {
153 EchoProxyInterface::r#echo_string(self, value)
154 }
155}
156
157impl EchoProxyInterface for EchoProxy {
158 type EchoStringResponseFut = fidl::client::QueryResponseFut<
159 Option<String>,
160 fidl::encoding::DefaultFuchsiaResourceDialect,
161 >;
162 fn r#echo_string(&self, mut value: Option<&str>) -> Self::EchoStringResponseFut {
163 fn _decode(
164 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
165 ) -> Result<Option<String>, fidl::Error> {
166 let _response = fidl::client::decode_transaction_body::<
167 EchoEchoStringResponse,
168 fidl::encoding::DefaultFuchsiaResourceDialect,
169 0x1e16cc1b194790f6,
170 >(_buf?)?;
171 Ok(_response.response)
172 }
173 self.client.send_query_and_decode::<EchoEchoStringRequest, Option<String>>(
174 (value,),
175 0x1e16cc1b194790f6,
176 fidl::encoding::DynamicFlags::empty(),
177 _decode,
178 )
179 }
180}
181
182pub struct EchoEventStream {
183 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
184}
185
186impl std::marker::Unpin for EchoEventStream {}
187
188impl futures::stream::FusedStream for EchoEventStream {
189 fn is_terminated(&self) -> bool {
190 self.event_receiver.is_terminated()
191 }
192}
193
194impl futures::Stream for EchoEventStream {
195 type Item = Result<EchoEvent, fidl::Error>;
196
197 fn poll_next(
198 mut self: std::pin::Pin<&mut Self>,
199 cx: &mut std::task::Context<'_>,
200 ) -> std::task::Poll<Option<Self::Item>> {
201 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
202 &mut self.event_receiver,
203 cx
204 )?) {
205 Some(buf) => std::task::Poll::Ready(Some(EchoEvent::decode(buf))),
206 None => std::task::Poll::Ready(None),
207 }
208 }
209}
210
211#[derive(Debug)]
212pub enum EchoEvent {}
213
214impl EchoEvent {
215 fn decode(
217 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
218 ) -> Result<EchoEvent, fidl::Error> {
219 let (bytes, _handles) = buf.split_mut();
220 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
221 debug_assert_eq!(tx_header.tx_id, 0);
222 match tx_header.ordinal {
223 _ => Err(fidl::Error::UnknownOrdinal {
224 ordinal: tx_header.ordinal,
225 protocol_name: <EchoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
226 }),
227 }
228 }
229}
230
231pub struct EchoRequestStream {
233 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
234 is_terminated: bool,
235}
236
237impl std::marker::Unpin for EchoRequestStream {}
238
239impl futures::stream::FusedStream for EchoRequestStream {
240 fn is_terminated(&self) -> bool {
241 self.is_terminated
242 }
243}
244
245impl fidl::endpoints::RequestStream for EchoRequestStream {
246 type Protocol = EchoMarker;
247 type ControlHandle = EchoControlHandle;
248
249 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
250 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
251 }
252
253 fn control_handle(&self) -> Self::ControlHandle {
254 EchoControlHandle { inner: self.inner.clone() }
255 }
256
257 fn into_inner(
258 self,
259 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
260 {
261 (self.inner, self.is_terminated)
262 }
263
264 fn from_inner(
265 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
266 is_terminated: bool,
267 ) -> Self {
268 Self { inner, is_terminated }
269 }
270}
271
272impl futures::Stream for EchoRequestStream {
273 type Item = Result<EchoRequest, fidl::Error>;
274
275 fn poll_next(
276 mut self: std::pin::Pin<&mut Self>,
277 cx: &mut std::task::Context<'_>,
278 ) -> std::task::Poll<Option<Self::Item>> {
279 let this = &mut *self;
280 if this.inner.check_shutdown(cx) {
281 this.is_terminated = true;
282 return std::task::Poll::Ready(None);
283 }
284 if this.is_terminated {
285 panic!("polled EchoRequestStream after completion");
286 }
287 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
288 |bytes, handles| {
289 match this.inner.channel().read_etc(cx, bytes, handles) {
290 std::task::Poll::Ready(Ok(())) => {}
291 std::task::Poll::Pending => return std::task::Poll::Pending,
292 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
293 this.is_terminated = true;
294 return std::task::Poll::Ready(None);
295 }
296 std::task::Poll::Ready(Err(e)) => {
297 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
298 e.into(),
299 ))))
300 }
301 }
302
303 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
305
306 std::task::Poll::Ready(Some(match header.ordinal {
307 0x1e16cc1b194790f6 => {
308 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
309 let mut req = fidl::new_empty!(
310 EchoEchoStringRequest,
311 fidl::encoding::DefaultFuchsiaResourceDialect
312 );
313 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EchoEchoStringRequest>(&header, _body_bytes, handles, &mut req)?;
314 let control_handle = EchoControlHandle { inner: this.inner.clone() };
315 Ok(EchoRequest::EchoString {
316 value: req.value,
317
318 responder: EchoEchoStringResponder {
319 control_handle: std::mem::ManuallyDrop::new(control_handle),
320 tx_id: header.tx_id,
321 },
322 })
323 }
324 _ => Err(fidl::Error::UnknownOrdinal {
325 ordinal: header.ordinal,
326 protocol_name: <EchoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327 }),
328 }))
329 },
330 )
331 }
332}
333
334#[derive(Debug)]
335pub enum EchoRequest {
336 EchoString { value: Option<String>, responder: EchoEchoStringResponder },
337}
338
339impl EchoRequest {
340 #[allow(irrefutable_let_patterns)]
341 pub fn into_echo_string(self) -> Option<(Option<String>, EchoEchoStringResponder)> {
342 if let EchoRequest::EchoString { value, responder } = self {
343 Some((value, responder))
344 } else {
345 None
346 }
347 }
348
349 pub fn method_name(&self) -> &'static str {
351 match *self {
352 EchoRequest::EchoString { .. } => "echo_string",
353 }
354 }
355}
356
357#[derive(Debug, Clone)]
358pub struct EchoControlHandle {
359 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
360}
361
362impl fidl::endpoints::ControlHandle for EchoControlHandle {
363 fn shutdown(&self) {
364 self.inner.shutdown()
365 }
366 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
367 self.inner.shutdown_with_epitaph(status)
368 }
369
370 fn is_closed(&self) -> bool {
371 self.inner.channel().is_closed()
372 }
373 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
374 self.inner.channel().on_closed()
375 }
376
377 #[cfg(target_os = "fuchsia")]
378 fn signal_peer(
379 &self,
380 clear_mask: zx::Signals,
381 set_mask: zx::Signals,
382 ) -> Result<(), zx_status::Status> {
383 use fidl::Peered;
384 self.inner.channel().signal_peer(clear_mask, set_mask)
385 }
386}
387
388impl EchoControlHandle {}
389
390#[must_use = "FIDL methods require a response to be sent"]
391#[derive(Debug)]
392pub struct EchoEchoStringResponder {
393 control_handle: std::mem::ManuallyDrop<EchoControlHandle>,
394 tx_id: u32,
395}
396
397impl std::ops::Drop for EchoEchoStringResponder {
401 fn drop(&mut self) {
402 self.control_handle.shutdown();
403 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
405 }
406}
407
408impl fidl::endpoints::Responder for EchoEchoStringResponder {
409 type ControlHandle = EchoControlHandle;
410
411 fn control_handle(&self) -> &EchoControlHandle {
412 &self.control_handle
413 }
414
415 fn drop_without_shutdown(mut self) {
416 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
418 std::mem::forget(self);
420 }
421}
422
423impl EchoEchoStringResponder {
424 pub fn send(self, mut response: Option<&str>) -> Result<(), fidl::Error> {
428 let _result = self.send_raw(response);
429 if _result.is_err() {
430 self.control_handle.shutdown();
431 }
432 self.drop_without_shutdown();
433 _result
434 }
435
436 pub fn send_no_shutdown_on_err(self, mut response: Option<&str>) -> Result<(), fidl::Error> {
438 let _result = self.send_raw(response);
439 self.drop_without_shutdown();
440 _result
441 }
442
443 fn send_raw(&self, mut response: Option<&str>) -> Result<(), fidl::Error> {
444 self.control_handle.inner.send::<EchoEchoStringResponse>(
445 (response,),
446 self.tx_id,
447 0x1e16cc1b194790f6,
448 fidl::encoding::DynamicFlags::empty(),
449 )
450 }
451}
452
453mod internal {
454 use super::*;
455}