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