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::NullableHandle {
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
405    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
406        self.inner.shutdown_with_epitaph(status)
407    }
408
409    fn is_closed(&self) -> bool {
410        self.inner.channel().is_closed()
411    }
412    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
413        self.inner.channel().on_closed()
414    }
415
416    #[cfg(target_os = "fuchsia")]
417    fn signal_peer(
418        &self,
419        clear_mask: zx::Signals,
420        set_mask: zx::Signals,
421    ) -> Result<(), zx_status::Status> {
422        use fidl::Peered;
423        self.inner.channel().signal_peer(clear_mask, set_mask)
424    }
425}
426
427impl PkgDirControlHandle {}
428
429#[must_use = "FIDL methods require a response to be sent"]
430#[derive(Debug)]
431pub struct PkgDirOpenPackageDirectoryResponder {
432    control_handle: std::mem::ManuallyDrop<PkgDirControlHandle>,
433    tx_id: u32,
434}
435
436/// Set the the channel to be shutdown (see [`PkgDirControlHandle::shutdown`])
437/// if the responder is dropped without sending a response, so that the client
438/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
439impl std::ops::Drop for PkgDirOpenPackageDirectoryResponder {
440    fn drop(&mut self) {
441        self.control_handle.shutdown();
442        // Safety: drops once, never accessed again
443        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
444    }
445}
446
447impl fidl::endpoints::Responder for PkgDirOpenPackageDirectoryResponder {
448    type ControlHandle = PkgDirControlHandle;
449
450    fn control_handle(&self) -> &PkgDirControlHandle {
451        &self.control_handle
452    }
453
454    fn drop_without_shutdown(mut self) {
455        // Safety: drops once, never accessed again due to mem::forget
456        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
457        // Prevent Drop from running (which would shut down the channel)
458        std::mem::forget(self);
459    }
460}
461
462impl PkgDirOpenPackageDirectoryResponder {
463    /// Sends a response to the FIDL transaction.
464    ///
465    /// Sets the channel to shutdown if an error occurs.
466    pub fn send(
467        self,
468        mut result: Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>,
469    ) -> Result<(), fidl::Error> {
470        let _result = self.send_raw(result);
471        if _result.is_err() {
472            self.control_handle.shutdown();
473        }
474        self.drop_without_shutdown();
475        _result
476    }
477
478    /// Similar to "send" but does not shutdown the channel if an error occurs.
479    pub fn send_no_shutdown_on_err(
480        self,
481        mut result: Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>,
482    ) -> Result<(), fidl::Error> {
483        let _result = self.send_raw(result);
484        self.drop_without_shutdown();
485        _result
486    }
487
488    fn send_raw(
489        &self,
490        mut result: Result<fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>, i32>,
491    ) -> Result<(), fidl::Error> {
492        self.control_handle
493            .inner
494            .send::<fidl::encoding::ResultType<PkgDirOpenPackageDirectoryResponse, i32>>(
495                result.map(|client_end| (client_end,)),
496                self.tx_id,
497                0x4589b1c39651e01,
498                fidl::encoding::DynamicFlags::empty(),
499            )
500    }
501}
502
503mod internal {
504    use super::*;
505
506    impl fidl::encoding::ResourceTypeMarker for PkgDirOpenPackageDirectoryResponse {
507        type Borrowed<'a> = &'a mut Self;
508        fn take_or_borrow<'a>(
509            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
510        ) -> Self::Borrowed<'a> {
511            value
512        }
513    }
514
515    unsafe impl fidl::encoding::TypeMarker for PkgDirOpenPackageDirectoryResponse {
516        type Owned = Self;
517
518        #[inline(always)]
519        fn inline_align(_context: fidl::encoding::Context) -> usize {
520            4
521        }
522
523        #[inline(always)]
524        fn inline_size(_context: fidl::encoding::Context) -> usize {
525            4
526        }
527    }
528
529    unsafe impl
530        fidl::encoding::Encode<
531            PkgDirOpenPackageDirectoryResponse,
532            fidl::encoding::DefaultFuchsiaResourceDialect,
533        > for &mut PkgDirOpenPackageDirectoryResponse
534    {
535        #[inline]
536        unsafe fn encode(
537            self,
538            encoder: &mut fidl::encoding::Encoder<
539                '_,
540                fidl::encoding::DefaultFuchsiaResourceDialect,
541            >,
542            offset: usize,
543            _depth: fidl::encoding::Depth,
544        ) -> fidl::Result<()> {
545            encoder.debug_check_bounds::<PkgDirOpenPackageDirectoryResponse>(offset);
546            // Delegate to tuple encoding.
547            fidl::encoding::Encode::<
548                PkgDirOpenPackageDirectoryResponse,
549                fidl::encoding::DefaultFuchsiaResourceDialect,
550            >::encode(
551                (<fidl::encoding::Endpoint<
552                    fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
553                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
554                    &mut self.client_end
555                ),),
556                encoder,
557                offset,
558                _depth,
559            )
560        }
561    }
562    unsafe impl<
563        T0: fidl::encoding::Encode<
564                fidl::encoding::Endpoint<
565                    fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
566                >,
567                fidl::encoding::DefaultFuchsiaResourceDialect,
568            >,
569    >
570        fidl::encoding::Encode<
571            PkgDirOpenPackageDirectoryResponse,
572            fidl::encoding::DefaultFuchsiaResourceDialect,
573        > for (T0,)
574    {
575        #[inline]
576        unsafe fn encode(
577            self,
578            encoder: &mut fidl::encoding::Encoder<
579                '_,
580                fidl::encoding::DefaultFuchsiaResourceDialect,
581            >,
582            offset: usize,
583            depth: fidl::encoding::Depth,
584        ) -> fidl::Result<()> {
585            encoder.debug_check_bounds::<PkgDirOpenPackageDirectoryResponse>(offset);
586            // Zero out padding regions. There's no need to apply masks
587            // because the unmasked parts will be overwritten by fields.
588            // Write the fields.
589            self.0.encode(encoder, offset + 0, depth)?;
590            Ok(())
591        }
592    }
593
594    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
595        for PkgDirOpenPackageDirectoryResponse
596    {
597        #[inline(always)]
598        fn new_empty() -> Self {
599            Self {
600                client_end: fidl::new_empty!(
601                    fidl::encoding::Endpoint<
602                        fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
603                    >,
604                    fidl::encoding::DefaultFuchsiaResourceDialect
605                ),
606            }
607        }
608
609        #[inline]
610        unsafe fn decode(
611            &mut self,
612            decoder: &mut fidl::encoding::Decoder<
613                '_,
614                fidl::encoding::DefaultFuchsiaResourceDialect,
615            >,
616            offset: usize,
617            _depth: fidl::encoding::Depth,
618        ) -> fidl::Result<()> {
619            decoder.debug_check_bounds::<Self>(offset);
620            // Verify that padding bytes are zero.
621            fidl::decode!(
622                fidl::encoding::Endpoint<
623                    fidl::endpoints::ClientEnd<fidl_fuchsia_io::DirectoryMarker>,
624                >,
625                fidl::encoding::DefaultFuchsiaResourceDialect,
626                &mut self.client_end,
627                decoder,
628                offset + 0,
629                _depth
630            )?;
631            Ok(())
632        }
633    }
634}