fidl_test_structuredconfig_receiver/
fidl_test_structuredconfig_receiver.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![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_structuredconfig_receiver__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ConfigReceiverPuppetMarker;
16
17impl fidl::endpoints::ProtocolMarker for ConfigReceiverPuppetMarker {
18    type Proxy = ConfigReceiverPuppetProxy;
19    type RequestStream = ConfigReceiverPuppetRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ConfigReceiverPuppetSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "test.structuredconfig.receiver.ConfigReceiverPuppet";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ConfigReceiverPuppetMarker {}
26
27pub trait ConfigReceiverPuppetProxyInterface: Send + Sync {
28    type GetConfigResponseFut: std::future::Future<Output = Result<ReceiverConfig, fidl::Error>>
29        + Send;
30    fn r#get_config(&self) -> Self::GetConfigResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct ConfigReceiverPuppetSynchronousProxy {
35    client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for ConfigReceiverPuppetSynchronousProxy {
40    type Proxy = ConfigReceiverPuppetProxy;
41    type Protocol = ConfigReceiverPuppetMarker;
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 ConfigReceiverPuppetSynchronousProxy {
58    pub fn new(channel: fidl::Channel) -> Self {
59        let protocol_name =
60            <ConfigReceiverPuppetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62    }
63
64    pub fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    /// Waits until an event arrives and returns it. It is safe for other
69    /// threads to make concurrent requests while waiting for an event.
70    pub fn wait_for_event(
71        &self,
72        deadline: zx::MonotonicInstant,
73    ) -> Result<ConfigReceiverPuppetEvent, fidl::Error> {
74        ConfigReceiverPuppetEvent::decode(self.client.wait_for_event(deadline)?)
75    }
76
77    pub fn r#get_config(
78        &self,
79        ___deadline: zx::MonotonicInstant,
80    ) -> Result<ReceiverConfig, fidl::Error> {
81        let _response = self
82            .client
83            .send_query::<fidl::encoding::EmptyPayload, ConfigReceiverPuppetGetConfigResponse>(
84                (),
85                0x243d8db8a2863b24,
86                fidl::encoding::DynamicFlags::empty(),
87                ___deadline,
88            )?;
89        Ok(_response.config)
90    }
91}
92
93#[cfg(target_os = "fuchsia")]
94impl From<ConfigReceiverPuppetSynchronousProxy> for zx::Handle {
95    fn from(value: ConfigReceiverPuppetSynchronousProxy) -> Self {
96        value.into_channel().into()
97    }
98}
99
100#[cfg(target_os = "fuchsia")]
101impl From<fidl::Channel> for ConfigReceiverPuppetSynchronousProxy {
102    fn from(value: fidl::Channel) -> Self {
103        Self::new(value)
104    }
105}
106
107#[cfg(target_os = "fuchsia")]
108impl fidl::endpoints::FromClient for ConfigReceiverPuppetSynchronousProxy {
109    type Protocol = ConfigReceiverPuppetMarker;
110
111    fn from_client(value: fidl::endpoints::ClientEnd<ConfigReceiverPuppetMarker>) -> Self {
112        Self::new(value.into_channel())
113    }
114}
115
116#[derive(Debug, Clone)]
117pub struct ConfigReceiverPuppetProxy {
118    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
119}
120
121impl fidl::endpoints::Proxy for ConfigReceiverPuppetProxy {
122    type Protocol = ConfigReceiverPuppetMarker;
123
124    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
125        Self::new(inner)
126    }
127
128    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
129        self.client.into_channel().map_err(|client| Self { client })
130    }
131
132    fn as_channel(&self) -> &::fidl::AsyncChannel {
133        self.client.as_channel()
134    }
135}
136
137impl ConfigReceiverPuppetProxy {
138    /// Create a new Proxy for test.structuredconfig.receiver/ConfigReceiverPuppet.
139    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
140        let protocol_name =
141            <ConfigReceiverPuppetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142        Self { client: fidl::client::Client::new(channel, protocol_name) }
143    }
144
145    /// Get a Stream of events from the remote end of the protocol.
146    ///
147    /// # Panics
148    ///
149    /// Panics if the event stream was already taken.
150    pub fn take_event_stream(&self) -> ConfigReceiverPuppetEventStream {
151        ConfigReceiverPuppetEventStream { event_receiver: self.client.take_event_receiver() }
152    }
153
154    pub fn r#get_config(
155        &self,
156    ) -> fidl::client::QueryResponseFut<ReceiverConfig, fidl::encoding::DefaultFuchsiaResourceDialect>
157    {
158        ConfigReceiverPuppetProxyInterface::r#get_config(self)
159    }
160}
161
162impl ConfigReceiverPuppetProxyInterface for ConfigReceiverPuppetProxy {
163    type GetConfigResponseFut = fidl::client::QueryResponseFut<
164        ReceiverConfig,
165        fidl::encoding::DefaultFuchsiaResourceDialect,
166    >;
167    fn r#get_config(&self) -> Self::GetConfigResponseFut {
168        fn _decode(
169            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
170        ) -> Result<ReceiverConfig, fidl::Error> {
171            let _response = fidl::client::decode_transaction_body::<
172                ConfigReceiverPuppetGetConfigResponse,
173                fidl::encoding::DefaultFuchsiaResourceDialect,
174                0x243d8db8a2863b24,
175            >(_buf?)?;
176            Ok(_response.config)
177        }
178        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ReceiverConfig>(
179            (),
180            0x243d8db8a2863b24,
181            fidl::encoding::DynamicFlags::empty(),
182            _decode,
183        )
184    }
185}
186
187pub struct ConfigReceiverPuppetEventStream {
188    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
189}
190
191impl std::marker::Unpin for ConfigReceiverPuppetEventStream {}
192
193impl futures::stream::FusedStream for ConfigReceiverPuppetEventStream {
194    fn is_terminated(&self) -> bool {
195        self.event_receiver.is_terminated()
196    }
197}
198
199impl futures::Stream for ConfigReceiverPuppetEventStream {
200    type Item = Result<ConfigReceiverPuppetEvent, fidl::Error>;
201
202    fn poll_next(
203        mut self: std::pin::Pin<&mut Self>,
204        cx: &mut std::task::Context<'_>,
205    ) -> std::task::Poll<Option<Self::Item>> {
206        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
207            &mut self.event_receiver,
208            cx
209        )?) {
210            Some(buf) => std::task::Poll::Ready(Some(ConfigReceiverPuppetEvent::decode(buf))),
211            None => std::task::Poll::Ready(None),
212        }
213    }
214}
215
216#[derive(Debug)]
217pub enum ConfigReceiverPuppetEvent {}
218
219impl ConfigReceiverPuppetEvent {
220    /// Decodes a message buffer as a [`ConfigReceiverPuppetEvent`].
221    fn decode(
222        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
223    ) -> Result<ConfigReceiverPuppetEvent, fidl::Error> {
224        let (bytes, _handles) = buf.split_mut();
225        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
226        debug_assert_eq!(tx_header.tx_id, 0);
227        match tx_header.ordinal {
228            _ => Err(fidl::Error::UnknownOrdinal {
229                ordinal: tx_header.ordinal,
230                protocol_name:
231                    <ConfigReceiverPuppetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
232            }),
233        }
234    }
235}
236
237/// A Stream of incoming requests for test.structuredconfig.receiver/ConfigReceiverPuppet.
238pub struct ConfigReceiverPuppetRequestStream {
239    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
240    is_terminated: bool,
241}
242
243impl std::marker::Unpin for ConfigReceiverPuppetRequestStream {}
244
245impl futures::stream::FusedStream for ConfigReceiverPuppetRequestStream {
246    fn is_terminated(&self) -> bool {
247        self.is_terminated
248    }
249}
250
251impl fidl::endpoints::RequestStream for ConfigReceiverPuppetRequestStream {
252    type Protocol = ConfigReceiverPuppetMarker;
253    type ControlHandle = ConfigReceiverPuppetControlHandle;
254
255    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
256        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
257    }
258
259    fn control_handle(&self) -> Self::ControlHandle {
260        ConfigReceiverPuppetControlHandle { inner: self.inner.clone() }
261    }
262
263    fn into_inner(
264        self,
265    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
266    {
267        (self.inner, self.is_terminated)
268    }
269
270    fn from_inner(
271        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
272        is_terminated: bool,
273    ) -> Self {
274        Self { inner, is_terminated }
275    }
276}
277
278impl futures::Stream for ConfigReceiverPuppetRequestStream {
279    type Item = Result<ConfigReceiverPuppetRequest, fidl::Error>;
280
281    fn poll_next(
282        mut self: std::pin::Pin<&mut Self>,
283        cx: &mut std::task::Context<'_>,
284    ) -> std::task::Poll<Option<Self::Item>> {
285        let this = &mut *self;
286        if this.inner.check_shutdown(cx) {
287            this.is_terminated = true;
288            return std::task::Poll::Ready(None);
289        }
290        if this.is_terminated {
291            panic!("polled ConfigReceiverPuppetRequestStream after completion");
292        }
293        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
294            |bytes, handles| {
295                match this.inner.channel().read_etc(cx, bytes, handles) {
296                    std::task::Poll::Ready(Ok(())) => {}
297                    std::task::Poll::Pending => return std::task::Poll::Pending,
298                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
299                        this.is_terminated = true;
300                        return std::task::Poll::Ready(None);
301                    }
302                    std::task::Poll::Ready(Err(e)) => {
303                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
304                            e.into(),
305                        ))))
306                    }
307                }
308
309                // A message has been received from the channel
310                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
311
312                std::task::Poll::Ready(Some(match header.ordinal {
313                0x243d8db8a2863b24 => {
314                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
315                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
316                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
317                    let control_handle = ConfigReceiverPuppetControlHandle {
318                        inner: this.inner.clone(),
319                    };
320                    Ok(ConfigReceiverPuppetRequest::GetConfig {
321                        responder: ConfigReceiverPuppetGetConfigResponder {
322                            control_handle: std::mem::ManuallyDrop::new(control_handle),
323                            tx_id: header.tx_id,
324                        },
325                    })
326                }
327                _ => Err(fidl::Error::UnknownOrdinal {
328                    ordinal: header.ordinal,
329                    protocol_name: <ConfigReceiverPuppetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
330                }),
331            }))
332            },
333        )
334    }
335}
336
337#[derive(Debug)]
338pub enum ConfigReceiverPuppetRequest {
339    GetConfig { responder: ConfigReceiverPuppetGetConfigResponder },
340}
341
342impl ConfigReceiverPuppetRequest {
343    #[allow(irrefutable_let_patterns)]
344    pub fn into_get_config(self) -> Option<(ConfigReceiverPuppetGetConfigResponder)> {
345        if let ConfigReceiverPuppetRequest::GetConfig { responder } = self {
346            Some((responder))
347        } else {
348            None
349        }
350    }
351
352    /// Name of the method defined in FIDL
353    pub fn method_name(&self) -> &'static str {
354        match *self {
355            ConfigReceiverPuppetRequest::GetConfig { .. } => "get_config",
356        }
357    }
358}
359
360#[derive(Debug, Clone)]
361pub struct ConfigReceiverPuppetControlHandle {
362    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
363}
364
365impl fidl::endpoints::ControlHandle for ConfigReceiverPuppetControlHandle {
366    fn shutdown(&self) {
367        self.inner.shutdown()
368    }
369    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
370        self.inner.shutdown_with_epitaph(status)
371    }
372
373    fn is_closed(&self) -> bool {
374        self.inner.channel().is_closed()
375    }
376    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
377        self.inner.channel().on_closed()
378    }
379
380    #[cfg(target_os = "fuchsia")]
381    fn signal_peer(
382        &self,
383        clear_mask: zx::Signals,
384        set_mask: zx::Signals,
385    ) -> Result<(), zx_status::Status> {
386        use fidl::Peered;
387        self.inner.channel().signal_peer(clear_mask, set_mask)
388    }
389}
390
391impl ConfigReceiverPuppetControlHandle {}
392
393#[must_use = "FIDL methods require a response to be sent"]
394#[derive(Debug)]
395pub struct ConfigReceiverPuppetGetConfigResponder {
396    control_handle: std::mem::ManuallyDrop<ConfigReceiverPuppetControlHandle>,
397    tx_id: u32,
398}
399
400/// Set the the channel to be shutdown (see [`ConfigReceiverPuppetControlHandle::shutdown`])
401/// if the responder is dropped without sending a response, so that the client
402/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
403impl std::ops::Drop for ConfigReceiverPuppetGetConfigResponder {
404    fn drop(&mut self) {
405        self.control_handle.shutdown();
406        // Safety: drops once, never accessed again
407        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
408    }
409}
410
411impl fidl::endpoints::Responder for ConfigReceiverPuppetGetConfigResponder {
412    type ControlHandle = ConfigReceiverPuppetControlHandle;
413
414    fn control_handle(&self) -> &ConfigReceiverPuppetControlHandle {
415        &self.control_handle
416    }
417
418    fn drop_without_shutdown(mut self) {
419        // Safety: drops once, never accessed again due to mem::forget
420        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
421        // Prevent Drop from running (which would shut down the channel)
422        std::mem::forget(self);
423    }
424}
425
426impl ConfigReceiverPuppetGetConfigResponder {
427    /// Sends a response to the FIDL transaction.
428    ///
429    /// Sets the channel to shutdown if an error occurs.
430    pub fn send(self, mut config: &ReceiverConfig) -> Result<(), fidl::Error> {
431        let _result = self.send_raw(config);
432        if _result.is_err() {
433            self.control_handle.shutdown();
434        }
435        self.drop_without_shutdown();
436        _result
437    }
438
439    /// Similar to "send" but does not shutdown the channel if an error occurs.
440    pub fn send_no_shutdown_on_err(self, mut config: &ReceiverConfig) -> Result<(), fidl::Error> {
441        let _result = self.send_raw(config);
442        self.drop_without_shutdown();
443        _result
444    }
445
446    fn send_raw(&self, mut config: &ReceiverConfig) -> Result<(), fidl::Error> {
447        self.control_handle.inner.send::<ConfigReceiverPuppetGetConfigResponse>(
448            (config,),
449            self.tx_id,
450            0x243d8db8a2863b24,
451            fidl::encoding::DynamicFlags::empty(),
452        )
453    }
454}
455
456mod internal {
457    use super::*;
458}