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_ping__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct PingMarker;
16
17impl fidl::endpoints::ProtocolMarker for PingMarker {
18 type Proxy = PingProxy;
19 type RequestStream = PingRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = PingSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "test.ping.Ping";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for PingMarker {}
26
27pub trait PingProxyInterface: Send + Sync {
28 type PingResponseFut: std::future::Future<Output = Result<String, fidl::Error>> + Send;
29 fn r#ping(&self, ping: &str) -> Self::PingResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct PingSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for PingSynchronousProxy {
39 type Proxy = PingProxy;
40 type Protocol = PingMarker;
41
42 fn from_channel(inner: fidl::Channel) -> Self {
43 Self::new(inner)
44 }
45
46 fn into_channel(self) -> fidl::Channel {
47 self.client.into_channel()
48 }
49
50 fn as_channel(&self) -> &fidl::Channel {
51 self.client.as_channel()
52 }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl PingSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <PingMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60 }
61
62 pub fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<PingEvent, fidl::Error> {
69 PingEvent::decode(self.client.wait_for_event(deadline)?)
70 }
71
72 pub fn r#ping(
75 &self,
76 mut ping: &str,
77 ___deadline: zx::MonotonicInstant,
78 ) -> Result<String, fidl::Error> {
79 let _response = self.client.send_query::<PingPingRequest, PingPingResponse>(
80 (ping,),
81 0x509ea7ec7cd43504,
82 fidl::encoding::DynamicFlags::empty(),
83 ___deadline,
84 )?;
85 Ok(_response.pong)
86 }
87}
88
89#[cfg(target_os = "fuchsia")]
90impl From<PingSynchronousProxy> for zx::Handle {
91 fn from(value: PingSynchronousProxy) -> Self {
92 value.into_channel().into()
93 }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<fidl::Channel> for PingSynchronousProxy {
98 fn from(value: fidl::Channel) -> Self {
99 Self::new(value)
100 }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl fidl::endpoints::FromClient for PingSynchronousProxy {
105 type Protocol = PingMarker;
106
107 fn from_client(value: fidl::endpoints::ClientEnd<PingMarker>) -> Self {
108 Self::new(value.into_channel())
109 }
110}
111
112#[derive(Debug, Clone)]
113pub struct PingProxy {
114 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
115}
116
117impl fidl::endpoints::Proxy for PingProxy {
118 type Protocol = PingMarker;
119
120 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
121 Self::new(inner)
122 }
123
124 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
125 self.client.into_channel().map_err(|client| Self { client })
126 }
127
128 fn as_channel(&self) -> &::fidl::AsyncChannel {
129 self.client.as_channel()
130 }
131}
132
133impl PingProxy {
134 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
136 let protocol_name = <PingMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
137 Self { client: fidl::client::Client::new(channel, protocol_name) }
138 }
139
140 pub fn take_event_stream(&self) -> PingEventStream {
146 PingEventStream { event_receiver: self.client.take_event_receiver() }
147 }
148
149 pub fn r#ping(
152 &self,
153 mut ping: &str,
154 ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
155 PingProxyInterface::r#ping(self, ping)
156 }
157}
158
159impl PingProxyInterface for PingProxy {
160 type PingResponseFut =
161 fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
162 fn r#ping(&self, mut ping: &str) -> Self::PingResponseFut {
163 fn _decode(
164 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
165 ) -> Result<String, fidl::Error> {
166 let _response = fidl::client::decode_transaction_body::<
167 PingPingResponse,
168 fidl::encoding::DefaultFuchsiaResourceDialect,
169 0x509ea7ec7cd43504,
170 >(_buf?)?;
171 Ok(_response.pong)
172 }
173 self.client.send_query_and_decode::<PingPingRequest, String>(
174 (ping,),
175 0x509ea7ec7cd43504,
176 fidl::encoding::DynamicFlags::empty(),
177 _decode,
178 )
179 }
180}
181
182pub struct PingEventStream {
183 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
184}
185
186impl std::marker::Unpin for PingEventStream {}
187
188impl futures::stream::FusedStream for PingEventStream {
189 fn is_terminated(&self) -> bool {
190 self.event_receiver.is_terminated()
191 }
192}
193
194impl futures::Stream for PingEventStream {
195 type Item = Result<PingEvent, 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(PingEvent::decode(buf))),
206 None => std::task::Poll::Ready(None),
207 }
208 }
209}
210
211#[derive(Debug)]
212pub enum PingEvent {}
213
214impl PingEvent {
215 fn decode(
217 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
218 ) -> Result<PingEvent, 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: <PingMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
226 }),
227 }
228 }
229}
230
231pub struct PingRequestStream {
233 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
234 is_terminated: bool,
235}
236
237impl std::marker::Unpin for PingRequestStream {}
238
239impl futures::stream::FusedStream for PingRequestStream {
240 fn is_terminated(&self) -> bool {
241 self.is_terminated
242 }
243}
244
245impl fidl::endpoints::RequestStream for PingRequestStream {
246 type Protocol = PingMarker;
247 type ControlHandle = PingControlHandle;
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 PingControlHandle { 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 PingRequestStream {
273 type Item = Result<PingRequest, 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 PingRequestStream 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 0x509ea7ec7cd43504 => {
308 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
309 let mut req = fidl::new_empty!(
310 PingPingRequest,
311 fidl::encoding::DefaultFuchsiaResourceDialect
312 );
313 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PingPingRequest>(&header, _body_bytes, handles, &mut req)?;
314 let control_handle = PingControlHandle { inner: this.inner.clone() };
315 Ok(PingRequest::Ping {
316 ping: req.ping,
317
318 responder: PingPingResponder {
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: <PingMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327 }),
328 }))
329 },
330 )
331 }
332}
333
334#[derive(Debug)]
335pub enum PingRequest {
336 Ping { ping: String, responder: PingPingResponder },
339}
340
341impl PingRequest {
342 #[allow(irrefutable_let_patterns)]
343 pub fn into_ping(self) -> Option<(String, PingPingResponder)> {
344 if let PingRequest::Ping { ping, responder } = self {
345 Some((ping, responder))
346 } else {
347 None
348 }
349 }
350
351 pub fn method_name(&self) -> &'static str {
353 match *self {
354 PingRequest::Ping { .. } => "ping",
355 }
356 }
357}
358
359#[derive(Debug, Clone)]
360pub struct PingControlHandle {
361 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
362}
363
364impl fidl::endpoints::ControlHandle for PingControlHandle {
365 fn shutdown(&self) {
366 self.inner.shutdown()
367 }
368 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
369 self.inner.shutdown_with_epitaph(status)
370 }
371
372 fn is_closed(&self) -> bool {
373 self.inner.channel().is_closed()
374 }
375 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
376 self.inner.channel().on_closed()
377 }
378
379 #[cfg(target_os = "fuchsia")]
380 fn signal_peer(
381 &self,
382 clear_mask: zx::Signals,
383 set_mask: zx::Signals,
384 ) -> Result<(), zx_status::Status> {
385 use fidl::Peered;
386 self.inner.channel().signal_peer(clear_mask, set_mask)
387 }
388}
389
390impl PingControlHandle {}
391
392#[must_use = "FIDL methods require a response to be sent"]
393#[derive(Debug)]
394pub struct PingPingResponder {
395 control_handle: std::mem::ManuallyDrop<PingControlHandle>,
396 tx_id: u32,
397}
398
399impl std::ops::Drop for PingPingResponder {
403 fn drop(&mut self) {
404 self.control_handle.shutdown();
405 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
407 }
408}
409
410impl fidl::endpoints::Responder for PingPingResponder {
411 type ControlHandle = PingControlHandle;
412
413 fn control_handle(&self) -> &PingControlHandle {
414 &self.control_handle
415 }
416
417 fn drop_without_shutdown(mut self) {
418 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
420 std::mem::forget(self);
422 }
423}
424
425impl PingPingResponder {
426 pub fn send(self, mut pong: &str) -> Result<(), fidl::Error> {
430 let _result = self.send_raw(pong);
431 if _result.is_err() {
432 self.control_handle.shutdown();
433 }
434 self.drop_without_shutdown();
435 _result
436 }
437
438 pub fn send_no_shutdown_on_err(self, mut pong: &str) -> Result<(), fidl::Error> {
440 let _result = self.send_raw(pong);
441 self.drop_without_shutdown();
442 _result
443 }
444
445 fn send_raw(&self, mut pong: &str) -> Result<(), fidl::Error> {
446 self.control_handle.inner.send::<PingPingResponse>(
447 (pong,),
448 self.tx_id,
449 0x509ea7ec7cd43504,
450 fidl::encoding::DynamicFlags::empty(),
451 )
452 }
453}
454
455mod internal {
456 use super::*;
457}