Skip to main content

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