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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14#[repr(C)]
15pub struct SimpleAddRequest {
16 pub augend: u8,
17 pub addend: u8,
18}
19
20impl fidl::Persistable for SimpleAddRequest {}
21
22#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
23#[repr(C)]
24pub struct SimpleAddResponse {
25 pub sum: u16,
26}
27
28impl fidl::Persistable for SimpleAddResponse {}
29
30#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
31pub struct SimpleMarker;
32
33impl fidl::endpoints::ProtocolMarker for SimpleMarker {
34 type Proxy = SimpleProxy;
35 type RequestStream = SimpleRequestStream;
36 #[cfg(target_os = "fuchsia")]
37 type SynchronousProxy = SimpleSynchronousProxy;
38
39 const DEBUG_NAME: &'static str = "test.exampletester.Simple";
40}
41impl fidl::endpoints::DiscoverableProtocolMarker for SimpleMarker {}
42
43pub trait SimpleProxyInterface: Send + Sync {
44 type AddResponseFut: std::future::Future<Output = Result<u16, fidl::Error>> + Send;
45 fn r#add(&self, augend: u8, addend: u8) -> Self::AddResponseFut;
46}
47#[derive(Debug)]
48#[cfg(target_os = "fuchsia")]
49pub struct SimpleSynchronousProxy {
50 client: fidl::client::sync::Client,
51}
52
53#[cfg(target_os = "fuchsia")]
54impl fidl::endpoints::SynchronousProxy for SimpleSynchronousProxy {
55 type Proxy = SimpleProxy;
56 type Protocol = SimpleMarker;
57
58 fn from_channel(inner: fidl::Channel) -> Self {
59 Self::new(inner)
60 }
61
62 fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 fn as_channel(&self) -> &fidl::Channel {
67 self.client.as_channel()
68 }
69}
70
71#[cfg(target_os = "fuchsia")]
72impl SimpleSynchronousProxy {
73 pub fn new(channel: fidl::Channel) -> Self {
74 let protocol_name = <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
75 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
76 }
77
78 pub fn into_channel(self) -> fidl::Channel {
79 self.client.into_channel()
80 }
81
82 pub fn wait_for_event(
85 &self,
86 deadline: zx::MonotonicInstant,
87 ) -> Result<SimpleEvent, fidl::Error> {
88 SimpleEvent::decode(self.client.wait_for_event(deadline)?)
89 }
90
91 pub fn r#add(
93 &self,
94 mut augend: u8,
95 mut addend: u8,
96 ___deadline: zx::MonotonicInstant,
97 ) -> Result<u16, fidl::Error> {
98 let _response = self.client.send_query::<SimpleAddRequest, SimpleAddResponse>(
99 (augend, addend),
100 0x6f3077f69a049823,
101 fidl::encoding::DynamicFlags::empty(),
102 ___deadline,
103 )?;
104 Ok(_response.sum)
105 }
106}
107
108#[derive(Debug, Clone)]
109pub struct SimpleProxy {
110 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
111}
112
113impl fidl::endpoints::Proxy for SimpleProxy {
114 type Protocol = SimpleMarker;
115
116 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
117 Self::new(inner)
118 }
119
120 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
121 self.client.into_channel().map_err(|client| Self { client })
122 }
123
124 fn as_channel(&self) -> &::fidl::AsyncChannel {
125 self.client.as_channel()
126 }
127}
128
129impl SimpleProxy {
130 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
132 let protocol_name = <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
133 Self { client: fidl::client::Client::new(channel, protocol_name) }
134 }
135
136 pub fn take_event_stream(&self) -> SimpleEventStream {
142 SimpleEventStream { event_receiver: self.client.take_event_receiver() }
143 }
144
145 pub fn r#add(
147 &self,
148 mut augend: u8,
149 mut addend: u8,
150 ) -> fidl::client::QueryResponseFut<u16, fidl::encoding::DefaultFuchsiaResourceDialect> {
151 SimpleProxyInterface::r#add(self, augend, addend)
152 }
153}
154
155impl SimpleProxyInterface for SimpleProxy {
156 type AddResponseFut =
157 fidl::client::QueryResponseFut<u16, fidl::encoding::DefaultFuchsiaResourceDialect>;
158 fn r#add(&self, mut augend: u8, mut addend: u8) -> Self::AddResponseFut {
159 fn _decode(
160 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
161 ) -> Result<u16, fidl::Error> {
162 let _response = fidl::client::decode_transaction_body::<
163 SimpleAddResponse,
164 fidl::encoding::DefaultFuchsiaResourceDialect,
165 0x6f3077f69a049823,
166 >(_buf?)?;
167 Ok(_response.sum)
168 }
169 self.client.send_query_and_decode::<SimpleAddRequest, u16>(
170 (augend, addend),
171 0x6f3077f69a049823,
172 fidl::encoding::DynamicFlags::empty(),
173 _decode,
174 )
175 }
176}
177
178pub struct SimpleEventStream {
179 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
180}
181
182impl std::marker::Unpin for SimpleEventStream {}
183
184impl futures::stream::FusedStream for SimpleEventStream {
185 fn is_terminated(&self) -> bool {
186 self.event_receiver.is_terminated()
187 }
188}
189
190impl futures::Stream for SimpleEventStream {
191 type Item = Result<SimpleEvent, fidl::Error>;
192
193 fn poll_next(
194 mut self: std::pin::Pin<&mut Self>,
195 cx: &mut std::task::Context<'_>,
196 ) -> std::task::Poll<Option<Self::Item>> {
197 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
198 &mut self.event_receiver,
199 cx
200 )?) {
201 Some(buf) => std::task::Poll::Ready(Some(SimpleEvent::decode(buf))),
202 None => std::task::Poll::Ready(None),
203 }
204 }
205}
206
207#[derive(Debug)]
208pub enum SimpleEvent {}
209
210impl SimpleEvent {
211 fn decode(
213 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
214 ) -> Result<SimpleEvent, fidl::Error> {
215 let (bytes, _handles) = buf.split_mut();
216 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
217 debug_assert_eq!(tx_header.tx_id, 0);
218 match tx_header.ordinal {
219 _ => Err(fidl::Error::UnknownOrdinal {
220 ordinal: tx_header.ordinal,
221 protocol_name: <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
222 }),
223 }
224 }
225}
226
227pub struct SimpleRequestStream {
229 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
230 is_terminated: bool,
231}
232
233impl std::marker::Unpin for SimpleRequestStream {}
234
235impl futures::stream::FusedStream for SimpleRequestStream {
236 fn is_terminated(&self) -> bool {
237 self.is_terminated
238 }
239}
240
241impl fidl::endpoints::RequestStream for SimpleRequestStream {
242 type Protocol = SimpleMarker;
243 type ControlHandle = SimpleControlHandle;
244
245 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
246 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
247 }
248
249 fn control_handle(&self) -> Self::ControlHandle {
250 SimpleControlHandle { inner: self.inner.clone() }
251 }
252
253 fn into_inner(
254 self,
255 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
256 {
257 (self.inner, self.is_terminated)
258 }
259
260 fn from_inner(
261 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
262 is_terminated: bool,
263 ) -> Self {
264 Self { inner, is_terminated }
265 }
266}
267
268impl futures::Stream for SimpleRequestStream {
269 type Item = Result<SimpleRequest, fidl::Error>;
270
271 fn poll_next(
272 mut self: std::pin::Pin<&mut Self>,
273 cx: &mut std::task::Context<'_>,
274 ) -> std::task::Poll<Option<Self::Item>> {
275 let this = &mut *self;
276 if this.inner.check_shutdown(cx) {
277 this.is_terminated = true;
278 return std::task::Poll::Ready(None);
279 }
280 if this.is_terminated {
281 panic!("polled SimpleRequestStream after completion");
282 }
283 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
284 |bytes, handles| {
285 match this.inner.channel().read_etc(cx, bytes, handles) {
286 std::task::Poll::Ready(Ok(())) => {}
287 std::task::Poll::Pending => return std::task::Poll::Pending,
288 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
289 this.is_terminated = true;
290 return std::task::Poll::Ready(None);
291 }
292 std::task::Poll::Ready(Err(e)) => {
293 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
294 e.into(),
295 ))))
296 }
297 }
298
299 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
301
302 std::task::Poll::Ready(Some(match header.ordinal {
303 0x6f3077f69a049823 => {
304 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
305 let mut req = fidl::new_empty!(
306 SimpleAddRequest,
307 fidl::encoding::DefaultFuchsiaResourceDialect
308 );
309 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SimpleAddRequest>(&header, _body_bytes, handles, &mut req)?;
310 let control_handle = SimpleControlHandle { inner: this.inner.clone() };
311 Ok(SimpleRequest::Add {
312 augend: req.augend,
313 addend: req.addend,
314
315 responder: SimpleAddResponder {
316 control_handle: std::mem::ManuallyDrop::new(control_handle),
317 tx_id: header.tx_id,
318 },
319 })
320 }
321 _ => Err(fidl::Error::UnknownOrdinal {
322 ordinal: header.ordinal,
323 protocol_name:
324 <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
325 }),
326 }))
327 },
328 )
329 }
330}
331
332#[derive(Debug)]
333pub enum SimpleRequest {
334 Add { augend: u8, addend: u8, responder: SimpleAddResponder },
336}
337
338impl SimpleRequest {
339 #[allow(irrefutable_let_patterns)]
340 pub fn into_add(self) -> Option<(u8, u8, SimpleAddResponder)> {
341 if let SimpleRequest::Add { augend, addend, responder } = self {
342 Some((augend, addend, responder))
343 } else {
344 None
345 }
346 }
347
348 pub fn method_name(&self) -> &'static str {
350 match *self {
351 SimpleRequest::Add { .. } => "add",
352 }
353 }
354}
355
356#[derive(Debug, Clone)]
357pub struct SimpleControlHandle {
358 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
359}
360
361impl fidl::endpoints::ControlHandle for SimpleControlHandle {
362 fn shutdown(&self) {
363 self.inner.shutdown()
364 }
365 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
366 self.inner.shutdown_with_epitaph(status)
367 }
368
369 fn is_closed(&self) -> bool {
370 self.inner.channel().is_closed()
371 }
372 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
373 self.inner.channel().on_closed()
374 }
375
376 #[cfg(target_os = "fuchsia")]
377 fn signal_peer(
378 &self,
379 clear_mask: zx::Signals,
380 set_mask: zx::Signals,
381 ) -> Result<(), zx_status::Status> {
382 use fidl::Peered;
383 self.inner.channel().signal_peer(clear_mask, set_mask)
384 }
385}
386
387impl SimpleControlHandle {}
388
389#[must_use = "FIDL methods require a response to be sent"]
390#[derive(Debug)]
391pub struct SimpleAddResponder {
392 control_handle: std::mem::ManuallyDrop<SimpleControlHandle>,
393 tx_id: u32,
394}
395
396impl std::ops::Drop for SimpleAddResponder {
400 fn drop(&mut self) {
401 self.control_handle.shutdown();
402 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
404 }
405}
406
407impl fidl::endpoints::Responder for SimpleAddResponder {
408 type ControlHandle = SimpleControlHandle;
409
410 fn control_handle(&self) -> &SimpleControlHandle {
411 &self.control_handle
412 }
413
414 fn drop_without_shutdown(mut self) {
415 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
417 std::mem::forget(self);
419 }
420}
421
422impl SimpleAddResponder {
423 pub fn send(self, mut sum: u16) -> Result<(), fidl::Error> {
427 let _result = self.send_raw(sum);
428 if _result.is_err() {
429 self.control_handle.shutdown();
430 }
431 self.drop_without_shutdown();
432 _result
433 }
434
435 pub fn send_no_shutdown_on_err(self, mut sum: u16) -> Result<(), fidl::Error> {
437 let _result = self.send_raw(sum);
438 self.drop_without_shutdown();
439 _result
440 }
441
442 fn send_raw(&self, mut sum: u16) -> Result<(), fidl::Error> {
443 self.control_handle.inner.send::<SimpleAddResponse>(
444 (sum,),
445 self.tx_id,
446 0x6f3077f69a049823,
447 fidl::encoding::DynamicFlags::empty(),
448 )
449 }
450}
451
452mod internal {
453 use super::*;
454
455 impl fidl::encoding::ValueTypeMarker for SimpleAddRequest {
456 type Borrowed<'a> = &'a Self;
457 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
458 value
459 }
460 }
461
462 unsafe impl fidl::encoding::TypeMarker for SimpleAddRequest {
463 type Owned = Self;
464
465 #[inline(always)]
466 fn inline_align(_context: fidl::encoding::Context) -> usize {
467 1
468 }
469
470 #[inline(always)]
471 fn inline_size(_context: fidl::encoding::Context) -> usize {
472 2
473 }
474 #[inline(always)]
475 fn encode_is_copy() -> bool {
476 true
477 }
478
479 #[inline(always)]
480 fn decode_is_copy() -> bool {
481 true
482 }
483 }
484
485 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SimpleAddRequest, D>
486 for &SimpleAddRequest
487 {
488 #[inline]
489 unsafe fn encode(
490 self,
491 encoder: &mut fidl::encoding::Encoder<'_, D>,
492 offset: usize,
493 _depth: fidl::encoding::Depth,
494 ) -> fidl::Result<()> {
495 encoder.debug_check_bounds::<SimpleAddRequest>(offset);
496 unsafe {
497 let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
499 (buf_ptr as *mut SimpleAddRequest)
500 .write_unaligned((self as *const SimpleAddRequest).read());
501 }
504 Ok(())
505 }
506 }
507 unsafe impl<
508 D: fidl::encoding::ResourceDialect,
509 T0: fidl::encoding::Encode<u8, D>,
510 T1: fidl::encoding::Encode<u8, D>,
511 > fidl::encoding::Encode<SimpleAddRequest, D> for (T0, T1)
512 {
513 #[inline]
514 unsafe fn encode(
515 self,
516 encoder: &mut fidl::encoding::Encoder<'_, D>,
517 offset: usize,
518 depth: fidl::encoding::Depth,
519 ) -> fidl::Result<()> {
520 encoder.debug_check_bounds::<SimpleAddRequest>(offset);
521 self.0.encode(encoder, offset + 0, depth)?;
525 self.1.encode(encoder, offset + 1, depth)?;
526 Ok(())
527 }
528 }
529
530 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SimpleAddRequest {
531 #[inline(always)]
532 fn new_empty() -> Self {
533 Self { augend: fidl::new_empty!(u8, D), addend: fidl::new_empty!(u8, D) }
534 }
535
536 #[inline]
537 unsafe fn decode(
538 &mut self,
539 decoder: &mut fidl::encoding::Decoder<'_, D>,
540 offset: usize,
541 _depth: fidl::encoding::Depth,
542 ) -> fidl::Result<()> {
543 decoder.debug_check_bounds::<Self>(offset);
544 let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
545 unsafe {
548 std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 2);
549 }
550 Ok(())
551 }
552 }
553
554 impl fidl::encoding::ValueTypeMarker for SimpleAddResponse {
555 type Borrowed<'a> = &'a Self;
556 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
557 value
558 }
559 }
560
561 unsafe impl fidl::encoding::TypeMarker for SimpleAddResponse {
562 type Owned = Self;
563
564 #[inline(always)]
565 fn inline_align(_context: fidl::encoding::Context) -> usize {
566 2
567 }
568
569 #[inline(always)]
570 fn inline_size(_context: fidl::encoding::Context) -> usize {
571 2
572 }
573 #[inline(always)]
574 fn encode_is_copy() -> bool {
575 true
576 }
577
578 #[inline(always)]
579 fn decode_is_copy() -> bool {
580 true
581 }
582 }
583
584 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SimpleAddResponse, D>
585 for &SimpleAddResponse
586 {
587 #[inline]
588 unsafe fn encode(
589 self,
590 encoder: &mut fidl::encoding::Encoder<'_, D>,
591 offset: usize,
592 _depth: fidl::encoding::Depth,
593 ) -> fidl::Result<()> {
594 encoder.debug_check_bounds::<SimpleAddResponse>(offset);
595 unsafe {
596 let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
598 (buf_ptr as *mut SimpleAddResponse)
599 .write_unaligned((self as *const SimpleAddResponse).read());
600 }
603 Ok(())
604 }
605 }
606 unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u16, D>>
607 fidl::encoding::Encode<SimpleAddResponse, D> for (T0,)
608 {
609 #[inline]
610 unsafe fn encode(
611 self,
612 encoder: &mut fidl::encoding::Encoder<'_, D>,
613 offset: usize,
614 depth: fidl::encoding::Depth,
615 ) -> fidl::Result<()> {
616 encoder.debug_check_bounds::<SimpleAddResponse>(offset);
617 self.0.encode(encoder, offset + 0, depth)?;
621 Ok(())
622 }
623 }
624
625 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SimpleAddResponse {
626 #[inline(always)]
627 fn new_empty() -> Self {
628 Self { sum: fidl::new_empty!(u16, D) }
629 }
630
631 #[inline]
632 unsafe fn decode(
633 &mut self,
634 decoder: &mut fidl::encoding::Decoder<'_, D>,
635 offset: usize,
636 _depth: fidl::encoding::Depth,
637 ) -> fidl::Result<()> {
638 decoder.debug_check_bounds::<Self>(offset);
639 let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
640 unsafe {
643 std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 2);
644 }
645 Ok(())
646 }
647 }
648}