Skip to main content

fidl_fuchsia_erofs/
fidl_fuchsia_erofs.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_fuchsia_erofs_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Default, PartialEq)]
15pub struct ErofsServeRequest {
16    /// The vmo with the contents of the erofs instance to serve. Erofs is read-only so the vmo
17    /// contents will not be modified.
18    pub backing_vmo: Option<fidl::Vmo>,
19    /// The server end of an initial directory connection to the root of the new filesystem.
20    /// This directory connection will only have read rights.
21    pub root: Option<fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>>,
22    #[doc(hidden)]
23    pub __source_breaking: fidl::marker::SourceBreaking,
24}
25
26impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ErofsServeRequest {}
27
28#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
29pub struct ErofsMarker;
30
31impl fidl::endpoints::ProtocolMarker for ErofsMarker {
32    type Proxy = ErofsProxy;
33    type RequestStream = ErofsRequestStream;
34    #[cfg(target_os = "fuchsia")]
35    type SynchronousProxy = ErofsSynchronousProxy;
36
37    const DEBUG_NAME: &'static str = "fuchsia.erofs.Erofs";
38}
39impl fidl::endpoints::DiscoverableProtocolMarker for ErofsMarker {}
40pub type ErofsServeResult = Result<(), i32>;
41
42pub trait ErofsProxyInterface: Send + Sync {
43    type ServeResponseFut: std::future::Future<Output = Result<ErofsServeResult, fidl::Error>>
44        + Send;
45    fn r#serve(&self, payload: ErofsServeRequest) -> Self::ServeResponseFut;
46}
47#[derive(Debug)]
48#[cfg(target_os = "fuchsia")]
49pub struct ErofsSynchronousProxy {
50    client: fidl::client::sync::Client,
51}
52
53#[cfg(target_os = "fuchsia")]
54impl fidl::endpoints::SynchronousProxy for ErofsSynchronousProxy {
55    type Proxy = ErofsProxy;
56    type Protocol = ErofsMarker;
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 ErofsSynchronousProxy {
73    pub fn new(channel: fidl::Channel) -> Self {
74        Self { client: fidl::client::sync::Client::new(channel) }
75    }
76
77    pub fn into_channel(self) -> fidl::Channel {
78        self.client.into_channel()
79    }
80
81    /// Waits until an event arrives and returns it. It is safe for other
82    /// threads to make concurrent requests while waiting for an event.
83    pub fn wait_for_event(
84        &self,
85        deadline: zx::MonotonicInstant,
86    ) -> Result<ErofsEvent, fidl::Error> {
87        ErofsEvent::decode(self.client.wait_for_event::<ErofsMarker>(deadline)?)
88    }
89
90    /// Serves a new erofs instance, on a backing_vmo which contains the contents of the
91    /// filesystem. If there is an error setting up the initial connection it will be returned and
92    /// the directory connection will be closed.
93    pub fn r#serve(
94        &self,
95        mut payload: ErofsServeRequest,
96        ___deadline: zx::MonotonicInstant,
97    ) -> Result<ErofsServeResult, fidl::Error> {
98        let _response = self.client.send_query::<
99            ErofsServeRequest,
100            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
101            ErofsMarker,
102        >(
103            &mut payload,
104            0x5fb0caf6fcd41317,
105            fidl::encoding::DynamicFlags::FLEXIBLE,
106            ___deadline,
107        )?
108        .into_result::<ErofsMarker>("serve")?;
109        Ok(_response.map(|x| x))
110    }
111}
112
113#[cfg(target_os = "fuchsia")]
114impl From<ErofsSynchronousProxy> for zx::NullableHandle {
115    fn from(value: ErofsSynchronousProxy) -> Self {
116        value.into_channel().into()
117    }
118}
119
120#[cfg(target_os = "fuchsia")]
121impl From<fidl::Channel> for ErofsSynchronousProxy {
122    fn from(value: fidl::Channel) -> Self {
123        Self::new(value)
124    }
125}
126
127#[cfg(target_os = "fuchsia")]
128impl fidl::endpoints::FromClient for ErofsSynchronousProxy {
129    type Protocol = ErofsMarker;
130
131    fn from_client(value: fidl::endpoints::ClientEnd<ErofsMarker>) -> Self {
132        Self::new(value.into_channel())
133    }
134}
135
136#[derive(Debug, Clone)]
137pub struct ErofsProxy {
138    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
139}
140
141impl fidl::endpoints::Proxy for ErofsProxy {
142    type Protocol = ErofsMarker;
143
144    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
145        Self::new(inner)
146    }
147
148    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
149        self.client.into_channel().map_err(|client| Self { client })
150    }
151
152    fn as_channel(&self) -> &::fidl::AsyncChannel {
153        self.client.as_channel()
154    }
155}
156
157impl ErofsProxy {
158    /// Create a new Proxy for fuchsia.erofs/Erofs.
159    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
160        let protocol_name = <ErofsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
161        Self { client: fidl::client::Client::new(channel, protocol_name) }
162    }
163
164    /// Get a Stream of events from the remote end of the protocol.
165    ///
166    /// # Panics
167    ///
168    /// Panics if the event stream was already taken.
169    pub fn take_event_stream(&self) -> ErofsEventStream {
170        ErofsEventStream { event_receiver: self.client.take_event_receiver() }
171    }
172
173    /// Serves a new erofs instance, on a backing_vmo which contains the contents of the
174    /// filesystem. If there is an error setting up the initial connection it will be returned and
175    /// the directory connection will be closed.
176    pub fn r#serve(
177        &self,
178        mut payload: ErofsServeRequest,
179    ) -> fidl::client::QueryResponseFut<
180        ErofsServeResult,
181        fidl::encoding::DefaultFuchsiaResourceDialect,
182    > {
183        ErofsProxyInterface::r#serve(self, payload)
184    }
185}
186
187impl ErofsProxyInterface for ErofsProxy {
188    type ServeResponseFut = fidl::client::QueryResponseFut<
189        ErofsServeResult,
190        fidl::encoding::DefaultFuchsiaResourceDialect,
191    >;
192    fn r#serve(&self, mut payload: ErofsServeRequest) -> Self::ServeResponseFut {
193        fn _decode(
194            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
195        ) -> Result<ErofsServeResult, fidl::Error> {
196            let _response = fidl::client::decode_transaction_body::<
197                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
198                fidl::encoding::DefaultFuchsiaResourceDialect,
199                0x5fb0caf6fcd41317,
200            >(_buf?)?
201            .into_result::<ErofsMarker>("serve")?;
202            Ok(_response.map(|x| x))
203        }
204        self.client.send_query_and_decode::<ErofsServeRequest, ErofsServeResult>(
205            &mut payload,
206            0x5fb0caf6fcd41317,
207            fidl::encoding::DynamicFlags::FLEXIBLE,
208            _decode,
209        )
210    }
211}
212
213pub struct ErofsEventStream {
214    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
215}
216
217impl std::marker::Unpin for ErofsEventStream {}
218
219impl futures::stream::FusedStream for ErofsEventStream {
220    fn is_terminated(&self) -> bool {
221        self.event_receiver.is_terminated()
222    }
223}
224
225impl futures::Stream for ErofsEventStream {
226    type Item = Result<ErofsEvent, fidl::Error>;
227
228    fn poll_next(
229        mut self: std::pin::Pin<&mut Self>,
230        cx: &mut std::task::Context<'_>,
231    ) -> std::task::Poll<Option<Self::Item>> {
232        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
233            &mut self.event_receiver,
234            cx
235        )?) {
236            Some(buf) => std::task::Poll::Ready(Some(ErofsEvent::decode(buf))),
237            None => std::task::Poll::Ready(None),
238        }
239    }
240}
241
242#[derive(Debug)]
243pub enum ErofsEvent {
244    #[non_exhaustive]
245    _UnknownEvent {
246        /// Ordinal of the event that was sent.
247        ordinal: u64,
248    },
249}
250
251impl ErofsEvent {
252    /// Decodes a message buffer as a [`ErofsEvent`].
253    fn decode(
254        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
255    ) -> Result<ErofsEvent, fidl::Error> {
256        let (bytes, _handles) = buf.split_mut();
257        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
258        debug_assert_eq!(tx_header.tx_id, 0);
259        match tx_header.ordinal {
260            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
261                Ok(ErofsEvent::_UnknownEvent { ordinal: tx_header.ordinal })
262            }
263            _ => Err(fidl::Error::UnknownOrdinal {
264                ordinal: tx_header.ordinal,
265                protocol_name: <ErofsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
266            }),
267        }
268    }
269}
270
271/// A Stream of incoming requests for fuchsia.erofs/Erofs.
272pub struct ErofsRequestStream {
273    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
274    is_terminated: bool,
275}
276
277impl std::marker::Unpin for ErofsRequestStream {}
278
279impl futures::stream::FusedStream for ErofsRequestStream {
280    fn is_terminated(&self) -> bool {
281        self.is_terminated
282    }
283}
284
285impl fidl::endpoints::RequestStream for ErofsRequestStream {
286    type Protocol = ErofsMarker;
287    type ControlHandle = ErofsControlHandle;
288
289    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
290        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
291    }
292
293    fn control_handle(&self) -> Self::ControlHandle {
294        ErofsControlHandle { inner: self.inner.clone() }
295    }
296
297    fn into_inner(
298        self,
299    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
300    {
301        (self.inner, self.is_terminated)
302    }
303
304    fn from_inner(
305        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
306        is_terminated: bool,
307    ) -> Self {
308        Self { inner, is_terminated }
309    }
310}
311
312impl futures::Stream for ErofsRequestStream {
313    type Item = Result<ErofsRequest, fidl::Error>;
314
315    fn poll_next(
316        mut self: std::pin::Pin<&mut Self>,
317        cx: &mut std::task::Context<'_>,
318    ) -> std::task::Poll<Option<Self::Item>> {
319        let this = &mut *self;
320        if this.inner.check_shutdown(cx) {
321            this.is_terminated = true;
322            return std::task::Poll::Ready(None);
323        }
324        if this.is_terminated {
325            panic!("polled ErofsRequestStream after completion");
326        }
327        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
328            |bytes, handles| {
329                match this.inner.channel().read_etc(cx, bytes, handles) {
330                    std::task::Poll::Ready(Ok(())) => {}
331                    std::task::Poll::Pending => return std::task::Poll::Pending,
332                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
333                        this.is_terminated = true;
334                        return std::task::Poll::Ready(None);
335                    }
336                    std::task::Poll::Ready(Err(e)) => {
337                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
338                            e.into(),
339                        ))));
340                    }
341                }
342
343                // A message has been received from the channel
344                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
345
346                std::task::Poll::Ready(Some(match header.ordinal {
347                    0x5fb0caf6fcd41317 => {
348                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
349                        let mut req = fidl::new_empty!(
350                            ErofsServeRequest,
351                            fidl::encoding::DefaultFuchsiaResourceDialect
352                        );
353                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ErofsServeRequest>(&header, _body_bytes, handles, &mut req)?;
354                        let control_handle = ErofsControlHandle { inner: this.inner.clone() };
355                        Ok(ErofsRequest::Serve {
356                            payload: req,
357                            responder: ErofsServeResponder {
358                                control_handle: std::mem::ManuallyDrop::new(control_handle),
359                                tx_id: header.tx_id,
360                            },
361                        })
362                    }
363                    _ if header.tx_id == 0
364                        && header
365                            .dynamic_flags()
366                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
367                    {
368                        Ok(ErofsRequest::_UnknownMethod {
369                            ordinal: header.ordinal,
370                            control_handle: ErofsControlHandle { inner: this.inner.clone() },
371                            method_type: fidl::MethodType::OneWay,
372                        })
373                    }
374                    _ if header
375                        .dynamic_flags()
376                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
377                    {
378                        this.inner.send_framework_err(
379                            fidl::encoding::FrameworkErr::UnknownMethod,
380                            header.tx_id,
381                            header.ordinal,
382                            header.dynamic_flags(),
383                            (bytes, handles),
384                        )?;
385                        Ok(ErofsRequest::_UnknownMethod {
386                            ordinal: header.ordinal,
387                            control_handle: ErofsControlHandle { inner: this.inner.clone() },
388                            method_type: fidl::MethodType::TwoWay,
389                        })
390                    }
391                    _ => Err(fidl::Error::UnknownOrdinal {
392                        ordinal: header.ordinal,
393                        protocol_name: <ErofsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
394                    }),
395                }))
396            },
397        )
398    }
399}
400
401/// Manage erofs instances.
402#[derive(Debug)]
403pub enum ErofsRequest {
404    /// Serves a new erofs instance, on a backing_vmo which contains the contents of the
405    /// filesystem. If there is an error setting up the initial connection it will be returned and
406    /// the directory connection will be closed.
407    Serve { payload: ErofsServeRequest, responder: ErofsServeResponder },
408    /// An interaction was received which does not match any known method.
409    #[non_exhaustive]
410    _UnknownMethod {
411        /// Ordinal of the method that was called.
412        ordinal: u64,
413        control_handle: ErofsControlHandle,
414        method_type: fidl::MethodType,
415    },
416}
417
418impl ErofsRequest {
419    #[allow(irrefutable_let_patterns)]
420    pub fn into_serve(self) -> Option<(ErofsServeRequest, ErofsServeResponder)> {
421        if let ErofsRequest::Serve { payload, responder } = self {
422            Some((payload, responder))
423        } else {
424            None
425        }
426    }
427
428    /// Name of the method defined in FIDL
429    pub fn method_name(&self) -> &'static str {
430        match *self {
431            ErofsRequest::Serve { .. } => "serve",
432            ErofsRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
433                "unknown one-way method"
434            }
435            ErofsRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
436                "unknown two-way method"
437            }
438        }
439    }
440}
441
442#[derive(Debug, Clone)]
443pub struct ErofsControlHandle {
444    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
445}
446
447impl ErofsControlHandle {
448    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
449        self.inner.shutdown_with_epitaph(status.into())
450    }
451}
452
453impl fidl::endpoints::ControlHandle for ErofsControlHandle {
454    fn shutdown(&self) {
455        self.inner.shutdown()
456    }
457
458    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
459        self.inner.shutdown_with_epitaph(status)
460    }
461
462    fn is_closed(&self) -> bool {
463        self.inner.channel().is_closed()
464    }
465    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
466        self.inner.channel().on_closed()
467    }
468
469    #[cfg(target_os = "fuchsia")]
470    fn signal_peer(
471        &self,
472        clear_mask: zx::Signals,
473        set_mask: zx::Signals,
474    ) -> Result<(), zx_status::Status> {
475        use fidl::Peered;
476        self.inner.channel().signal_peer(clear_mask, set_mask)
477    }
478}
479
480impl ErofsControlHandle {}
481
482#[must_use = "FIDL methods require a response to be sent"]
483#[derive(Debug)]
484pub struct ErofsServeResponder {
485    control_handle: std::mem::ManuallyDrop<ErofsControlHandle>,
486    tx_id: u32,
487}
488
489/// Set the the channel to be shutdown (see [`ErofsControlHandle::shutdown`])
490/// if the responder is dropped without sending a response, so that the client
491/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
492impl std::ops::Drop for ErofsServeResponder {
493    fn drop(&mut self) {
494        self.control_handle.shutdown();
495        // Safety: drops once, never accessed again
496        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
497    }
498}
499
500impl fidl::endpoints::Responder for ErofsServeResponder {
501    type ControlHandle = ErofsControlHandle;
502
503    fn control_handle(&self) -> &ErofsControlHandle {
504        &self.control_handle
505    }
506
507    fn drop_without_shutdown(mut self) {
508        // Safety: drops once, never accessed again due to mem::forget
509        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
510        // Prevent Drop from running (which would shut down the channel)
511        std::mem::forget(self);
512    }
513}
514
515impl ErofsServeResponder {
516    /// Sends a response to the FIDL transaction.
517    ///
518    /// Sets the channel to shutdown if an error occurs.
519    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
520        let _result = self.send_raw(result);
521        if _result.is_err() {
522            self.control_handle.shutdown();
523        }
524        self.drop_without_shutdown();
525        _result
526    }
527
528    /// Similar to "send" but does not shutdown the channel if an error occurs.
529    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
530        let _result = self.send_raw(result);
531        self.drop_without_shutdown();
532        _result
533    }
534
535    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
536        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
537            fidl::encoding::EmptyStruct,
538            i32,
539        >>(
540            fidl::encoding::FlexibleResult::new(result),
541            self.tx_id,
542            0x5fb0caf6fcd41317,
543            fidl::encoding::DynamicFlags::FLEXIBLE,
544        )
545    }
546}
547
548mod internal {
549    use super::*;
550
551    impl ErofsServeRequest {
552        #[inline(always)]
553        fn max_ordinal_present(&self) -> u64 {
554            if let Some(_) = self.root {
555                return 3;
556            }
557            if let Some(_) = self.backing_vmo {
558                return 1;
559            }
560            0
561        }
562    }
563
564    impl fidl::encoding::ResourceTypeMarker for ErofsServeRequest {
565        type Borrowed<'a> = &'a mut Self;
566        fn take_or_borrow<'a>(
567            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
568        ) -> Self::Borrowed<'a> {
569            value
570        }
571    }
572
573    unsafe impl fidl::encoding::TypeMarker for ErofsServeRequest {
574        type Owned = Self;
575
576        #[inline(always)]
577        fn inline_align(_context: fidl::encoding::Context) -> usize {
578            8
579        }
580
581        #[inline(always)]
582        fn inline_size(_context: fidl::encoding::Context) -> usize {
583            16
584        }
585    }
586
587    unsafe impl
588        fidl::encoding::Encode<ErofsServeRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
589        for &mut ErofsServeRequest
590    {
591        unsafe fn encode(
592            self,
593            encoder: &mut fidl::encoding::Encoder<
594                '_,
595                fidl::encoding::DefaultFuchsiaResourceDialect,
596            >,
597            offset: usize,
598            mut depth: fidl::encoding::Depth,
599        ) -> fidl::Result<()> {
600            encoder.debug_check_bounds::<ErofsServeRequest>(offset);
601            // Vector header
602            let max_ordinal: u64 = self.max_ordinal_present();
603            encoder.write_num(max_ordinal, offset);
604            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
605            // Calling encoder.out_of_line_offset(0) is not allowed.
606            if max_ordinal == 0 {
607                return Ok(());
608            }
609            depth.increment()?;
610            let envelope_size = 8;
611            let bytes_len = max_ordinal as usize * envelope_size;
612            #[allow(unused_variables)]
613            let offset = encoder.out_of_line_offset(bytes_len);
614            let mut _prev_end_offset: usize = 0;
615            if 1 > max_ordinal {
616                return Ok(());
617            }
618
619            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
620            // are envelope_size bytes.
621            let cur_offset: usize = (1 - 1) * envelope_size;
622
623            // Zero reserved fields.
624            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
625
626            // Safety:
627            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
628            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
629            //   envelope_size bytes, there is always sufficient room.
630            fidl::encoding::encode_in_envelope_optional::<
631                fidl::encoding::HandleType<
632                    fidl::Vmo,
633                    { fidl::ObjectType::VMO.into_raw() },
634                    2147483648,
635                >,
636                fidl::encoding::DefaultFuchsiaResourceDialect,
637            >(
638                self.backing_vmo.as_mut().map(
639                    <fidl::encoding::HandleType<
640                        fidl::Vmo,
641                        { fidl::ObjectType::VMO.into_raw() },
642                        2147483648,
643                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
644                ),
645                encoder,
646                offset + cur_offset,
647                depth,
648            )?;
649
650            _prev_end_offset = cur_offset + envelope_size;
651            if 3 > max_ordinal {
652                return Ok(());
653            }
654
655            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
656            // are envelope_size bytes.
657            let cur_offset: usize = (3 - 1) * envelope_size;
658
659            // Zero reserved fields.
660            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
661
662            // Safety:
663            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
664            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
665            //   envelope_size bytes, there is always sufficient room.
666            fidl::encoding::encode_in_envelope_optional::<
667                fidl::encoding::Endpoint<
668                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
669                >,
670                fidl::encoding::DefaultFuchsiaResourceDialect,
671            >(
672                self.root.as_mut().map(
673                    <fidl::encoding::Endpoint<
674                        fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
675                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
676                ),
677                encoder,
678                offset + cur_offset,
679                depth,
680            )?;
681
682            _prev_end_offset = cur_offset + envelope_size;
683
684            Ok(())
685        }
686    }
687
688    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
689        for ErofsServeRequest
690    {
691        #[inline(always)]
692        fn new_empty() -> Self {
693            Self::default()
694        }
695
696        unsafe fn decode(
697            &mut self,
698            decoder: &mut fidl::encoding::Decoder<
699                '_,
700                fidl::encoding::DefaultFuchsiaResourceDialect,
701            >,
702            offset: usize,
703            mut depth: fidl::encoding::Depth,
704        ) -> fidl::Result<()> {
705            decoder.debug_check_bounds::<Self>(offset);
706            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
707                None => return Err(fidl::Error::NotNullable),
708                Some(len) => len,
709            };
710            // Calling decoder.out_of_line_offset(0) is not allowed.
711            if len == 0 {
712                return Ok(());
713            };
714            depth.increment()?;
715            let envelope_size = 8;
716            let bytes_len = len * envelope_size;
717            let offset = decoder.out_of_line_offset(bytes_len)?;
718            // Decode the envelope for each type.
719            let mut _next_ordinal_to_read = 0;
720            let mut next_offset = offset;
721            let end_offset = offset + bytes_len;
722            _next_ordinal_to_read += 1;
723            if next_offset >= end_offset {
724                return Ok(());
725            }
726
727            // Decode unknown envelopes for gaps in ordinals.
728            while _next_ordinal_to_read < 1 {
729                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
730                _next_ordinal_to_read += 1;
731                next_offset += envelope_size;
732            }
733
734            let next_out_of_line = decoder.next_out_of_line();
735            let handles_before = decoder.remaining_handles();
736            if let Some((inlined, num_bytes, num_handles)) =
737                fidl::encoding::decode_envelope_header(decoder, next_offset)?
738            {
739                let member_inline_size = <fidl::encoding::HandleType<
740                    fidl::Vmo,
741                    { fidl::ObjectType::VMO.into_raw() },
742                    2147483648,
743                > as fidl::encoding::TypeMarker>::inline_size(
744                    decoder.context
745                );
746                if inlined != (member_inline_size <= 4) {
747                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
748                }
749                let inner_offset;
750                let mut inner_depth = depth.clone();
751                if inlined {
752                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
753                    inner_offset = next_offset;
754                } else {
755                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
756                    inner_depth.increment()?;
757                }
758                let val_ref =
759                self.backing_vmo.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect));
760                fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
761                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
762                {
763                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
764                }
765                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
766                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
767                }
768            }
769
770            next_offset += envelope_size;
771            _next_ordinal_to_read += 1;
772            if next_offset >= end_offset {
773                return Ok(());
774            }
775
776            // Decode unknown envelopes for gaps in ordinals.
777            while _next_ordinal_to_read < 3 {
778                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
779                _next_ordinal_to_read += 1;
780                next_offset += envelope_size;
781            }
782
783            let next_out_of_line = decoder.next_out_of_line();
784            let handles_before = decoder.remaining_handles();
785            if let Some((inlined, num_bytes, num_handles)) =
786                fidl::encoding::decode_envelope_header(decoder, next_offset)?
787            {
788                let member_inline_size = <fidl::encoding::Endpoint<
789                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
790                > as fidl::encoding::TypeMarker>::inline_size(
791                    decoder.context
792                );
793                if inlined != (member_inline_size <= 4) {
794                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
795                }
796                let inner_offset;
797                let mut inner_depth = depth.clone();
798                if inlined {
799                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
800                    inner_offset = next_offset;
801                } else {
802                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
803                    inner_depth.increment()?;
804                }
805                let val_ref = self.root.get_or_insert_with(|| {
806                    fidl::new_empty!(
807                        fidl::encoding::Endpoint<
808                            fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
809                        >,
810                        fidl::encoding::DefaultFuchsiaResourceDialect
811                    )
812                });
813                fidl::decode!(
814                    fidl::encoding::Endpoint<
815                        fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
816                    >,
817                    fidl::encoding::DefaultFuchsiaResourceDialect,
818                    val_ref,
819                    decoder,
820                    inner_offset,
821                    inner_depth
822                )?;
823                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
824                {
825                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
826                }
827                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
828                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
829                }
830            }
831
832            next_offset += envelope_size;
833
834            // Decode the remaining unknown envelopes.
835            while next_offset < end_offset {
836                _next_ordinal_to_read += 1;
837                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
838                next_offset += envelope_size;
839            }
840
841            Ok(())
842        }
843    }
844}