fidl_test_pkgdir/
fidl_test_pkgdir.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_pkgdir__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct PkgDirOpenPackageDirectoryResponse {
16    pub client_end: fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for PkgDirOpenPackageDirectoryResponse
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct PkgDirMarker;
26
27impl fidl::endpoints::ProtocolMarker for PkgDirMarker {
28    type Proxy = PkgDirProxy;
29    type RequestStream = PkgDirRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = PkgDirSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "test.pkgdir.PkgDir";
34}
35impl fidl::endpoints::DiscoverableProtocolMarker for PkgDirMarker {}
36pub type PkgDirOpenPackageDirectoryResult =
37    Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>;
38
39pub trait PkgDirProxyInterface: Send + Sync {
40    type OpenPackageDirectoryResponseFut: std::future::Future<Output = Result<PkgDirOpenPackageDirectoryResult, fidl::Error>>
41        + Send;
42    fn r#open_package_directory(
43        &self,
44        meta_far: &[u8; 32],
45    ) -> Self::OpenPackageDirectoryResponseFut;
46}
47#[derive(Debug)]
48#[cfg(target_os = "fuchsia")]
49pub struct PkgDirSynchronousProxy {
50    client: fidl::client::sync::Client,
51}
52
53#[cfg(target_os = "fuchsia")]
54impl fidl::endpoints::SynchronousProxy for PkgDirSynchronousProxy {
55    type Proxy = PkgDirProxy;
56    type Protocol = PkgDirMarker;
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 PkgDirSynchronousProxy {
73    pub fn new(channel: fidl::Channel) -> Self {
74        let protocol_name = <PkgDirMarker 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    /// Waits until an event arrives and returns it. It is safe for other
83    /// threads to make concurrent requests while waiting for an event.
84    pub fn wait_for_event(
85        &self,
86        deadline: zx::MonotonicInstant,
87    ) -> Result<PkgDirEvent, fidl::Error> {
88        PkgDirEvent::decode(self.client.wait_for_event(deadline)?)
89    }
90
91    /// Serves a package directory for the package with hash meta_far and returns a
92    /// client end to the package directory.
93    pub fn r#open_package_directory(
94        &self,
95        mut meta_far: &[u8; 32],
96        ___deadline: zx::MonotonicInstant,
97    ) -> Result<PkgDirOpenPackageDirectoryResult, fidl::Error> {
98        let _response = self.client.send_query::<
99            PkgDirOpenPackageDirectoryRequest,
100            fidl::encoding::ResultType<PkgDirOpenPackageDirectoryResponse, i32>,
101        >(
102            (meta_far,),
103            0x4589b1c39651e01,
104            fidl::encoding::DynamicFlags::empty(),
105            ___deadline,
106        )?;
107        Ok(_response.map(|x| x.client_end))
108    }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl From<PkgDirSynchronousProxy> for zx::Handle {
113    fn from(value: PkgDirSynchronousProxy) -> Self {
114        value.into_channel().into()
115    }
116}
117
118#[cfg(target_os = "fuchsia")]
119impl From<fidl::Channel> for PkgDirSynchronousProxy {
120    fn from(value: fidl::Channel) -> Self {
121        Self::new(value)
122    }
123}
124
125#[cfg(target_os = "fuchsia")]
126impl fidl::endpoints::FromClient for PkgDirSynchronousProxy {
127    type Protocol = PkgDirMarker;
128
129    fn from_client(value: fidl::endpoints::ClientEnd<PkgDirMarker>) -> Self {
130        Self::new(value.into_channel())
131    }
132}
133
134#[derive(Debug, Clone)]
135pub struct PkgDirProxy {
136    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
137}
138
139impl fidl::endpoints::Proxy for PkgDirProxy {
140    type Protocol = PkgDirMarker;
141
142    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
143        Self::new(inner)
144    }
145
146    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
147        self.client.into_channel().map_err(|client| Self { client })
148    }
149
150    fn as_channel(&self) -> &::fidl::AsyncChannel {
151        self.client.as_channel()
152    }
153}
154
155impl PkgDirProxy {
156    /// Create a new Proxy for test.pkgdir/PkgDir.
157    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
158        let protocol_name = <PkgDirMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
159        Self { client: fidl::client::Client::new(channel, protocol_name) }
160    }
161
162    /// Get a Stream of events from the remote end of the protocol.
163    ///
164    /// # Panics
165    ///
166    /// Panics if the event stream was already taken.
167    pub fn take_event_stream(&self) -> PkgDirEventStream {
168        PkgDirEventStream { event_receiver: self.client.take_event_receiver() }
169    }
170
171    /// Serves a package directory for the package with hash meta_far and returns a
172    /// client end to the package directory.
173    pub fn r#open_package_directory(
174        &self,
175        mut meta_far: &[u8; 32],
176    ) -> fidl::client::QueryResponseFut<
177        PkgDirOpenPackageDirectoryResult,
178        fidl::encoding::DefaultFuchsiaResourceDialect,
179    > {
180        PkgDirProxyInterface::r#open_package_directory(self, meta_far)
181    }
182}
183
184impl PkgDirProxyInterface for PkgDirProxy {
185    type OpenPackageDirectoryResponseFut = fidl::client::QueryResponseFut<
186        PkgDirOpenPackageDirectoryResult,
187        fidl::encoding::DefaultFuchsiaResourceDialect,
188    >;
189    fn r#open_package_directory(
190        &self,
191        mut meta_far: &[u8; 32],
192    ) -> Self::OpenPackageDirectoryResponseFut {
193        fn _decode(
194            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
195        ) -> Result<PkgDirOpenPackageDirectoryResult, fidl::Error> {
196            let _response = fidl::client::decode_transaction_body::<
197                fidl::encoding::ResultType<PkgDirOpenPackageDirectoryResponse, i32>,
198                fidl::encoding::DefaultFuchsiaResourceDialect,
199                0x4589b1c39651e01,
200            >(_buf?)?;
201            Ok(_response.map(|x| x.client_end))
202        }
203        self.client.send_query_and_decode::<
204            PkgDirOpenPackageDirectoryRequest,
205            PkgDirOpenPackageDirectoryResult,
206        >(
207            (meta_far,),
208            0x4589b1c39651e01,
209            fidl::encoding::DynamicFlags::empty(),
210            _decode,
211        )
212    }
213}
214
215pub struct PkgDirEventStream {
216    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
217}
218
219impl std::marker::Unpin for PkgDirEventStream {}
220
221impl futures::stream::FusedStream for PkgDirEventStream {
222    fn is_terminated(&self) -> bool {
223        self.event_receiver.is_terminated()
224    }
225}
226
227impl futures::Stream for PkgDirEventStream {
228    type Item = Result<PkgDirEvent, fidl::Error>;
229
230    fn poll_next(
231        mut self: std::pin::Pin<&mut Self>,
232        cx: &mut std::task::Context<'_>,
233    ) -> std::task::Poll<Option<Self::Item>> {
234        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
235            &mut self.event_receiver,
236            cx
237        )?) {
238            Some(buf) => std::task::Poll::Ready(Some(PkgDirEvent::decode(buf))),
239            None => std::task::Poll::Ready(None),
240        }
241    }
242}
243
244#[derive(Debug)]
245pub enum PkgDirEvent {}
246
247impl PkgDirEvent {
248    /// Decodes a message buffer as a [`PkgDirEvent`].
249    fn decode(
250        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
251    ) -> Result<PkgDirEvent, fidl::Error> {
252        let (bytes, _handles) = buf.split_mut();
253        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
254        debug_assert_eq!(tx_header.tx_id, 0);
255        match tx_header.ordinal {
256            _ => Err(fidl::Error::UnknownOrdinal {
257                ordinal: tx_header.ordinal,
258                protocol_name: <PkgDirMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
259            }),
260        }
261    }
262}
263
264/// A Stream of incoming requests for test.pkgdir/PkgDir.
265pub struct PkgDirRequestStream {
266    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
267    is_terminated: bool,
268}
269
270impl std::marker::Unpin for PkgDirRequestStream {}
271
272impl futures::stream::FusedStream for PkgDirRequestStream {
273    fn is_terminated(&self) -> bool {
274        self.is_terminated
275    }
276}
277
278impl fidl::endpoints::RequestStream for PkgDirRequestStream {
279    type Protocol = PkgDirMarker;
280    type ControlHandle = PkgDirControlHandle;
281
282    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
283        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
284    }
285
286    fn control_handle(&self) -> Self::ControlHandle {
287        PkgDirControlHandle { inner: self.inner.clone() }
288    }
289
290    fn into_inner(
291        self,
292    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
293    {
294        (self.inner, self.is_terminated)
295    }
296
297    fn from_inner(
298        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
299        is_terminated: bool,
300    ) -> Self {
301        Self { inner, is_terminated }
302    }
303}
304
305impl futures::Stream for PkgDirRequestStream {
306    type Item = Result<PkgDirRequest, fidl::Error>;
307
308    fn poll_next(
309        mut self: std::pin::Pin<&mut Self>,
310        cx: &mut std::task::Context<'_>,
311    ) -> std::task::Poll<Option<Self::Item>> {
312        let this = &mut *self;
313        if this.inner.check_shutdown(cx) {
314            this.is_terminated = true;
315            return std::task::Poll::Ready(None);
316        }
317        if this.is_terminated {
318            panic!("polled PkgDirRequestStream after completion");
319        }
320        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
321            |bytes, handles| {
322                match this.inner.channel().read_etc(cx, bytes, handles) {
323                    std::task::Poll::Ready(Ok(())) => {}
324                    std::task::Poll::Pending => return std::task::Poll::Pending,
325                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
326                        this.is_terminated = true;
327                        return std::task::Poll::Ready(None);
328                    }
329                    std::task::Poll::Ready(Err(e)) => {
330                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
331                            e.into(),
332                        ))))
333                    }
334                }
335
336                // A message has been received from the channel
337                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
338
339                std::task::Poll::Ready(Some(match header.ordinal {
340                    0x4589b1c39651e01 => {
341                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
342                        let mut req = fidl::new_empty!(
343                            PkgDirOpenPackageDirectoryRequest,
344                            fidl::encoding::DefaultFuchsiaResourceDialect
345                        );
346                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PkgDirOpenPackageDirectoryRequest>(&header, _body_bytes, handles, &mut req)?;
347                        let control_handle = PkgDirControlHandle { inner: this.inner.clone() };
348                        Ok(PkgDirRequest::OpenPackageDirectory {
349                            meta_far: req.meta_far,
350
351                            responder: PkgDirOpenPackageDirectoryResponder {
352                                control_handle: std::mem::ManuallyDrop::new(control_handle),
353                                tx_id: header.tx_id,
354                            },
355                        })
356                    }
357                    _ => Err(fidl::Error::UnknownOrdinal {
358                        ordinal: header.ordinal,
359                        protocol_name:
360                            <PkgDirMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
361                    }),
362                }))
363            },
364        )
365    }
366}
367
368#[derive(Debug)]
369pub enum PkgDirRequest {
370    /// Serves a package directory for the package with hash meta_far and returns a
371    /// client end to the package directory.
372    OpenPackageDirectory { meta_far: [u8; 32], responder: PkgDirOpenPackageDirectoryResponder },
373}
374
375impl PkgDirRequest {
376    #[allow(irrefutable_let_patterns)]
377    pub fn into_open_package_directory(
378        self,
379    ) -> Option<([u8; 32], PkgDirOpenPackageDirectoryResponder)> {
380        if let PkgDirRequest::OpenPackageDirectory { meta_far, responder } = self {
381            Some((meta_far, responder))
382        } else {
383            None
384        }
385    }
386
387    /// Name of the method defined in FIDL
388    pub fn method_name(&self) -> &'static str {
389        match *self {
390            PkgDirRequest::OpenPackageDirectory { .. } => "open_package_directory",
391        }
392    }
393}
394
395#[derive(Debug, Clone)]
396pub struct PkgDirControlHandle {
397    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
398}
399
400impl fidl::endpoints::ControlHandle for PkgDirControlHandle {
401    fn shutdown(&self) {
402        self.inner.shutdown()
403    }
404    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
405        self.inner.shutdown_with_epitaph(status)
406    }
407
408    fn is_closed(&self) -> bool {
409        self.inner.channel().is_closed()
410    }
411    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
412        self.inner.channel().on_closed()
413    }
414
415    #[cfg(target_os = "fuchsia")]
416    fn signal_peer(
417        &self,
418        clear_mask: zx::Signals,
419        set_mask: zx::Signals,
420    ) -> Result<(), zx_status::Status> {
421        use fidl::Peered;
422        self.inner.channel().signal_peer(clear_mask, set_mask)
423    }
424}
425
426impl PkgDirControlHandle {}
427
428#[must_use = "FIDL methods require a response to be sent"]
429#[derive(Debug)]
430pub struct PkgDirOpenPackageDirectoryResponder {
431    control_handle: std::mem::ManuallyDrop<PkgDirControlHandle>,
432    tx_id: u32,
433}
434
435/// Set the the channel to be shutdown (see [`PkgDirControlHandle::shutdown`])
436/// if the responder is dropped without sending a response, so that the client
437/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
438impl std::ops::Drop for PkgDirOpenPackageDirectoryResponder {
439    fn drop(&mut self) {
440        self.control_handle.shutdown();
441        // Safety: drops once, never accessed again
442        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
443    }
444}
445
446impl fidl::endpoints::Responder for PkgDirOpenPackageDirectoryResponder {
447    type ControlHandle = PkgDirControlHandle;
448
449    fn control_handle(&self) -> &PkgDirControlHandle {
450        &self.control_handle
451    }
452
453    fn drop_without_shutdown(mut self) {
454        // Safety: drops once, never accessed again due to mem::forget
455        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
456        // Prevent Drop from running (which would shut down the channel)
457        std::mem::forget(self);
458    }
459}
460
461impl PkgDirOpenPackageDirectoryResponder {
462    /// Sends a response to the FIDL transaction.
463    ///
464    /// Sets the channel to shutdown if an error occurs.
465    pub fn send(
466        self,
467        mut result: Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>,
468    ) -> Result<(), fidl::Error> {
469        let _result = self.send_raw(result);
470        if _result.is_err() {
471            self.control_handle.shutdown();
472        }
473        self.drop_without_shutdown();
474        _result
475    }
476
477    /// Similar to "send" but does not shutdown the channel if an error occurs.
478    pub fn send_no_shutdown_on_err(
479        self,
480        mut result: Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>,
481    ) -> Result<(), fidl::Error> {
482        let _result = self.send_raw(result);
483        self.drop_without_shutdown();
484        _result
485    }
486
487    fn send_raw(
488        &self,
489        mut result: Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>,
490    ) -> Result<(), fidl::Error> {
491        self.control_handle
492            .inner
493            .send::<fidl::encoding::ResultType<PkgDirOpenPackageDirectoryResponse, i32>>(
494                result.map(|client_end| (client_end,)),
495                self.tx_id,
496                0x4589b1c39651e01,
497                fidl::encoding::DynamicFlags::empty(),
498            )
499    }
500}
501
502mod internal {
503    use super::*;
504
505    impl fidl::encoding::ResourceTypeMarker for PkgDirOpenPackageDirectoryResponse {
506        type Borrowed<'a> = &'a mut Self;
507        fn take_or_borrow<'a>(
508            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
509        ) -> Self::Borrowed<'a> {
510            value
511        }
512    }
513
514    unsafe impl fidl::encoding::TypeMarker for PkgDirOpenPackageDirectoryResponse {
515        type Owned = Self;
516
517        #[inline(always)]
518        fn inline_align(_context: fidl::encoding::Context) -> usize {
519            4
520        }
521
522        #[inline(always)]
523        fn inline_size(_context: fidl::encoding::Context) -> usize {
524            4
525        }
526    }
527
528    unsafe impl
529        fidl::encoding::Encode<
530            PkgDirOpenPackageDirectoryResponse,
531            fidl::encoding::DefaultFuchsiaResourceDialect,
532        > for &mut PkgDirOpenPackageDirectoryResponse
533    {
534        #[inline]
535        unsafe fn encode(
536            self,
537            encoder: &mut fidl::encoding::Encoder<
538                '_,
539                fidl::encoding::DefaultFuchsiaResourceDialect,
540            >,
541            offset: usize,
542            _depth: fidl::encoding::Depth,
543        ) -> fidl::Result<()> {
544            encoder.debug_check_bounds::<PkgDirOpenPackageDirectoryResponse>(offset);
545            // Delegate to tuple encoding.
546            fidl::encoding::Encode::<
547                PkgDirOpenPackageDirectoryResponse,
548                fidl::encoding::DefaultFuchsiaResourceDialect,
549            >::encode(
550                (<fidl::encoding::Endpoint<
551                    fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
552                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
553                    &mut self.client_end
554                ),),
555                encoder,
556                offset,
557                _depth,
558            )
559        }
560    }
561    unsafe impl<
562            T0: fidl::encoding::Encode<
563                fidl::encoding::Endpoint<
564                    fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
565                >,
566                fidl::encoding::DefaultFuchsiaResourceDialect,
567            >,
568        >
569        fidl::encoding::Encode<
570            PkgDirOpenPackageDirectoryResponse,
571            fidl::encoding::DefaultFuchsiaResourceDialect,
572        > for (T0,)
573    {
574        #[inline]
575        unsafe fn encode(
576            self,
577            encoder: &mut fidl::encoding::Encoder<
578                '_,
579                fidl::encoding::DefaultFuchsiaResourceDialect,
580            >,
581            offset: usize,
582            depth: fidl::encoding::Depth,
583        ) -> fidl::Result<()> {
584            encoder.debug_check_bounds::<PkgDirOpenPackageDirectoryResponse>(offset);
585            // Zero out padding regions. There's no need to apply masks
586            // because the unmasked parts will be overwritten by fields.
587            // Write the fields.
588            self.0.encode(encoder, offset + 0, depth)?;
589            Ok(())
590        }
591    }
592
593    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
594        for PkgDirOpenPackageDirectoryResponse
595    {
596        #[inline(always)]
597        fn new_empty() -> Self {
598            Self {
599                client_end: fidl::new_empty!(
600                    fidl::encoding::Endpoint<
601                        fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
602                    >,
603                    fidl::encoding::DefaultFuchsiaResourceDialect
604                ),
605            }
606        }
607
608        #[inline]
609        unsafe fn decode(
610            &mut self,
611            decoder: &mut fidl::encoding::Decoder<
612                '_,
613                fidl::encoding::DefaultFuchsiaResourceDialect,
614            >,
615            offset: usize,
616            _depth: fidl::encoding::Depth,
617        ) -> fidl::Result<()> {
618            decoder.debug_check_bounds::<Self>(offset);
619            // Verify that padding bytes are zero.
620            fidl::decode!(
621                fidl::encoding::Endpoint<
622                    fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
623                >,
624                fidl::encoding::DefaultFuchsiaResourceDialect,
625                &mut self.client_end,
626                decoder,
627                offset + 0,
628                _depth
629            )?;
630            Ok(())
631        }
632    }
633}