Skip to main content

fidl_fuchsia_firmware_crash/
fidl_fuchsia_firmware_crash.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_firmware_crash__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct WatcherGetCrashEventResponse {
16    pub event: fidl::EventPair,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for WatcherGetCrashEventResponse
21{
22}
23
24#[derive(Debug, Default, PartialEq)]
25pub struct Crash {
26    /// Name or identifier for the subsystem which crashed.
27    pub subsystem_name: Option<String>,
28    /// Approximate timestamp when the crash occurred.
29    pub timestamp: Option<fidl::BootInstant>,
30    /// The description or code indicating why the crash occurred.
31    pub reason: Option<String>,
32    /// The number of times this subsystem has crashed.
33    /// Note that this is ignored if supplied by in Reporter.Report and instead
34    /// aggregated by the protocol implementer based on subsystem_name.
35    pub count: Option<u32>,
36    /// Optional version of the subsystem's firmware.
37    pub firmware_version: Option<String>,
38    /// Optional dump of the subsystem's failure. Not available on user builds.
39    pub crash_dump: Option<fidl::Vmo>,
40    #[doc(hidden)]
41    pub __source_breaking: fidl::marker::SourceBreaking,
42}
43
44impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Crash {}
45
46#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
47pub struct ReporterMarker;
48
49impl fidl::endpoints::ProtocolMarker for ReporterMarker {
50    type Proxy = ReporterProxy;
51    type RequestStream = ReporterRequestStream;
52    #[cfg(target_os = "fuchsia")]
53    type SynchronousProxy = ReporterSynchronousProxy;
54
55    const DEBUG_NAME: &'static str = "fuchsia.firmware.crash.Reporter";
56}
57impl fidl::endpoints::DiscoverableProtocolMarker for ReporterMarker {}
58
59pub trait ReporterProxyInterface: Send + Sync {
60    fn r#report(&self, payload: Crash) -> Result<(), fidl::Error>;
61}
62#[derive(Debug)]
63#[cfg(target_os = "fuchsia")]
64pub struct ReporterSynchronousProxy {
65    client: fidl::client::sync::Client,
66}
67
68#[cfg(target_os = "fuchsia")]
69impl fidl::endpoints::SynchronousProxy for ReporterSynchronousProxy {
70    type Proxy = ReporterProxy;
71    type Protocol = ReporterMarker;
72
73    fn from_channel(inner: fidl::Channel) -> Self {
74        Self::new(inner)
75    }
76
77    fn into_channel(self) -> fidl::Channel {
78        self.client.into_channel()
79    }
80
81    fn as_channel(&self) -> &fidl::Channel {
82        self.client.as_channel()
83    }
84}
85
86#[cfg(target_os = "fuchsia")]
87impl ReporterSynchronousProxy {
88    pub fn new(channel: fidl::Channel) -> Self {
89        let protocol_name = <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
90        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
91    }
92
93    pub fn into_channel(self) -> fidl::Channel {
94        self.client.into_channel()
95    }
96
97    /// Waits until an event arrives and returns it. It is safe for other
98    /// threads to make concurrent requests while waiting for an event.
99    pub fn wait_for_event(
100        &self,
101        deadline: zx::MonotonicInstant,
102    ) -> Result<ReporterEvent, fidl::Error> {
103        ReporterEvent::decode(self.client.wait_for_event(deadline)?)
104    }
105
106    /// Report a subsystem firmware crash.
107    pub fn r#report(&self, mut payload: Crash) -> Result<(), fidl::Error> {
108        self.client.send::<Crash>(
109            &mut payload,
110            0x6283d741761d9fe5,
111            fidl::encoding::DynamicFlags::FLEXIBLE,
112        )
113    }
114}
115
116#[cfg(target_os = "fuchsia")]
117impl From<ReporterSynchronousProxy> for zx::NullableHandle {
118    fn from(value: ReporterSynchronousProxy) -> Self {
119        value.into_channel().into()
120    }
121}
122
123#[cfg(target_os = "fuchsia")]
124impl From<fidl::Channel> for ReporterSynchronousProxy {
125    fn from(value: fidl::Channel) -> Self {
126        Self::new(value)
127    }
128}
129
130#[cfg(target_os = "fuchsia")]
131impl fidl::endpoints::FromClient for ReporterSynchronousProxy {
132    type Protocol = ReporterMarker;
133
134    fn from_client(value: fidl::endpoints::ClientEnd<ReporterMarker>) -> Self {
135        Self::new(value.into_channel())
136    }
137}
138
139#[derive(Debug, Clone)]
140pub struct ReporterProxy {
141    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
142}
143
144impl fidl::endpoints::Proxy for ReporterProxy {
145    type Protocol = ReporterMarker;
146
147    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
148        Self::new(inner)
149    }
150
151    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
152        self.client.into_channel().map_err(|client| Self { client })
153    }
154
155    fn as_channel(&self) -> &::fidl::AsyncChannel {
156        self.client.as_channel()
157    }
158}
159
160impl ReporterProxy {
161    /// Create a new Proxy for fuchsia.firmware.crash/Reporter.
162    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
163        let protocol_name = <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
164        Self { client: fidl::client::Client::new(channel, protocol_name) }
165    }
166
167    /// Get a Stream of events from the remote end of the protocol.
168    ///
169    /// # Panics
170    ///
171    /// Panics if the event stream was already taken.
172    pub fn take_event_stream(&self) -> ReporterEventStream {
173        ReporterEventStream { event_receiver: self.client.take_event_receiver() }
174    }
175
176    /// Report a subsystem firmware crash.
177    pub fn r#report(&self, mut payload: Crash) -> Result<(), fidl::Error> {
178        ReporterProxyInterface::r#report(self, payload)
179    }
180}
181
182impl ReporterProxyInterface for ReporterProxy {
183    fn r#report(&self, mut payload: Crash) -> Result<(), fidl::Error> {
184        self.client.send::<Crash>(
185            &mut payload,
186            0x6283d741761d9fe5,
187            fidl::encoding::DynamicFlags::FLEXIBLE,
188        )
189    }
190}
191
192pub struct ReporterEventStream {
193    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
194}
195
196impl std::marker::Unpin for ReporterEventStream {}
197
198impl futures::stream::FusedStream for ReporterEventStream {
199    fn is_terminated(&self) -> bool {
200        self.event_receiver.is_terminated()
201    }
202}
203
204impl futures::Stream for ReporterEventStream {
205    type Item = Result<ReporterEvent, fidl::Error>;
206
207    fn poll_next(
208        mut self: std::pin::Pin<&mut Self>,
209        cx: &mut std::task::Context<'_>,
210    ) -> std::task::Poll<Option<Self::Item>> {
211        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
212            &mut self.event_receiver,
213            cx
214        )?) {
215            Some(buf) => std::task::Poll::Ready(Some(ReporterEvent::decode(buf))),
216            None => std::task::Poll::Ready(None),
217        }
218    }
219}
220
221#[derive(Debug)]
222pub enum ReporterEvent {
223    #[non_exhaustive]
224    _UnknownEvent {
225        /// Ordinal of the event that was sent.
226        ordinal: u64,
227    },
228}
229
230impl ReporterEvent {
231    /// Decodes a message buffer as a [`ReporterEvent`].
232    fn decode(
233        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
234    ) -> Result<ReporterEvent, fidl::Error> {
235        let (bytes, _handles) = buf.split_mut();
236        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
237        debug_assert_eq!(tx_header.tx_id, 0);
238        match tx_header.ordinal {
239            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
240                Ok(ReporterEvent::_UnknownEvent { ordinal: tx_header.ordinal })
241            }
242            _ => Err(fidl::Error::UnknownOrdinal {
243                ordinal: tx_header.ordinal,
244                protocol_name: <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
245            }),
246        }
247    }
248}
249
250/// A Stream of incoming requests for fuchsia.firmware.crash/Reporter.
251pub struct ReporterRequestStream {
252    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
253    is_terminated: bool,
254}
255
256impl std::marker::Unpin for ReporterRequestStream {}
257
258impl futures::stream::FusedStream for ReporterRequestStream {
259    fn is_terminated(&self) -> bool {
260        self.is_terminated
261    }
262}
263
264impl fidl::endpoints::RequestStream for ReporterRequestStream {
265    type Protocol = ReporterMarker;
266    type ControlHandle = ReporterControlHandle;
267
268    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
269        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
270    }
271
272    fn control_handle(&self) -> Self::ControlHandle {
273        ReporterControlHandle { inner: self.inner.clone() }
274    }
275
276    fn into_inner(
277        self,
278    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
279    {
280        (self.inner, self.is_terminated)
281    }
282
283    fn from_inner(
284        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
285        is_terminated: bool,
286    ) -> Self {
287        Self { inner, is_terminated }
288    }
289}
290
291impl futures::Stream for ReporterRequestStream {
292    type Item = Result<ReporterRequest, fidl::Error>;
293
294    fn poll_next(
295        mut self: std::pin::Pin<&mut Self>,
296        cx: &mut std::task::Context<'_>,
297    ) -> std::task::Poll<Option<Self::Item>> {
298        let this = &mut *self;
299        if this.inner.check_shutdown(cx) {
300            this.is_terminated = true;
301            return std::task::Poll::Ready(None);
302        }
303        if this.is_terminated {
304            panic!("polled ReporterRequestStream after completion");
305        }
306        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
307            |bytes, handles| {
308                match this.inner.channel().read_etc(cx, bytes, handles) {
309                    std::task::Poll::Ready(Ok(())) => {}
310                    std::task::Poll::Pending => return std::task::Poll::Pending,
311                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
312                        this.is_terminated = true;
313                        return std::task::Poll::Ready(None);
314                    }
315                    std::task::Poll::Ready(Err(e)) => {
316                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
317                            e.into(),
318                        ))));
319                    }
320                }
321
322                // A message has been received from the channel
323                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
324
325                std::task::Poll::Ready(Some(match header.ordinal {
326                    0x6283d741761d9fe5 => {
327                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
328                        let mut req =
329                            fidl::new_empty!(Crash, fidl::encoding::DefaultFuchsiaResourceDialect);
330                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<Crash>(&header, _body_bytes, handles, &mut req)?;
331                        let control_handle = ReporterControlHandle { inner: this.inner.clone() };
332                        Ok(ReporterRequest::Report { payload: req, control_handle })
333                    }
334                    _ if header.tx_id == 0
335                        && header
336                            .dynamic_flags()
337                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
338                    {
339                        Ok(ReporterRequest::_UnknownMethod {
340                            ordinal: header.ordinal,
341                            control_handle: ReporterControlHandle { inner: this.inner.clone() },
342                            method_type: fidl::MethodType::OneWay,
343                        })
344                    }
345                    _ if header
346                        .dynamic_flags()
347                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
348                    {
349                        this.inner.send_framework_err(
350                            fidl::encoding::FrameworkErr::UnknownMethod,
351                            header.tx_id,
352                            header.ordinal,
353                            header.dynamic_flags(),
354                            (bytes, handles),
355                        )?;
356                        Ok(ReporterRequest::_UnknownMethod {
357                            ordinal: header.ordinal,
358                            control_handle: ReporterControlHandle { inner: this.inner.clone() },
359                            method_type: fidl::MethodType::TwoWay,
360                        })
361                    }
362                    _ => Err(fidl::Error::UnknownOrdinal {
363                        ordinal: header.ordinal,
364                        protocol_name:
365                            <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
366                    }),
367                }))
368            },
369        )
370    }
371}
372
373#[derive(Debug)]
374pub enum ReporterRequest {
375    /// Report a subsystem firmware crash.
376    Report { payload: Crash, control_handle: ReporterControlHandle },
377    /// An interaction was received which does not match any known method.
378    #[non_exhaustive]
379    _UnknownMethod {
380        /// Ordinal of the method that was called.
381        ordinal: u64,
382        control_handle: ReporterControlHandle,
383        method_type: fidl::MethodType,
384    },
385}
386
387impl ReporterRequest {
388    #[allow(irrefutable_let_patterns)]
389    pub fn into_report(self) -> Option<(Crash, ReporterControlHandle)> {
390        if let ReporterRequest::Report { payload, control_handle } = self {
391            Some((payload, control_handle))
392        } else {
393            None
394        }
395    }
396
397    /// Name of the method defined in FIDL
398    pub fn method_name(&self) -> &'static str {
399        match *self {
400            ReporterRequest::Report { .. } => "report",
401            ReporterRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
402                "unknown one-way method"
403            }
404            ReporterRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
405                "unknown two-way method"
406            }
407        }
408    }
409}
410
411#[derive(Debug, Clone)]
412pub struct ReporterControlHandle {
413    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
414}
415
416impl fidl::endpoints::ControlHandle for ReporterControlHandle {
417    fn shutdown(&self) {
418        self.inner.shutdown()
419    }
420
421    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
422        self.inner.shutdown_with_epitaph(status)
423    }
424
425    fn is_closed(&self) -> bool {
426        self.inner.channel().is_closed()
427    }
428    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
429        self.inner.channel().on_closed()
430    }
431
432    #[cfg(target_os = "fuchsia")]
433    fn signal_peer(
434        &self,
435        clear_mask: zx::Signals,
436        set_mask: zx::Signals,
437    ) -> Result<(), zx_status::Status> {
438        use fidl::Peered;
439        self.inner.channel().signal_peer(clear_mask, set_mask)
440    }
441}
442
443impl ReporterControlHandle {}
444
445#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
446pub struct WatcherMarker;
447
448impl fidl::endpoints::ProtocolMarker for WatcherMarker {
449    type Proxy = WatcherProxy;
450    type RequestStream = WatcherRequestStream;
451    #[cfg(target_os = "fuchsia")]
452    type SynchronousProxy = WatcherSynchronousProxy;
453
454    const DEBUG_NAME: &'static str = "fuchsia.firmware.crash.Watcher";
455}
456impl fidl::endpoints::DiscoverableProtocolMarker for WatcherMarker {}
457pub type WatcherGetCrashResult = Result<Crash, Error>;
458
459pub trait WatcherProxyInterface: Send + Sync {
460    type GetCrashResponseFut: std::future::Future<Output = Result<WatcherGetCrashResult, fidl::Error>>
461        + Send;
462    fn r#get_crash(&self, payload: &WatcherGetCrashRequest) -> Self::GetCrashResponseFut;
463    type GetCrashEventResponseFut: std::future::Future<Output = Result<fidl::EventPair, fidl::Error>>
464        + Send;
465    fn r#get_crash_event(&self) -> Self::GetCrashEventResponseFut;
466}
467#[derive(Debug)]
468#[cfg(target_os = "fuchsia")]
469pub struct WatcherSynchronousProxy {
470    client: fidl::client::sync::Client,
471}
472
473#[cfg(target_os = "fuchsia")]
474impl fidl::endpoints::SynchronousProxy for WatcherSynchronousProxy {
475    type Proxy = WatcherProxy;
476    type Protocol = WatcherMarker;
477
478    fn from_channel(inner: fidl::Channel) -> Self {
479        Self::new(inner)
480    }
481
482    fn into_channel(self) -> fidl::Channel {
483        self.client.into_channel()
484    }
485
486    fn as_channel(&self) -> &fidl::Channel {
487        self.client.as_channel()
488    }
489}
490
491#[cfg(target_os = "fuchsia")]
492impl WatcherSynchronousProxy {
493    pub fn new(channel: fidl::Channel) -> Self {
494        let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
495        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
496    }
497
498    pub fn into_channel(self) -> fidl::Channel {
499        self.client.into_channel()
500    }
501
502    /// Waits until an event arrives and returns it. It is safe for other
503    /// threads to make concurrent requests while waiting for an event.
504    pub fn wait_for_event(
505        &self,
506        deadline: zx::MonotonicInstant,
507    ) -> Result<WatcherEvent, fidl::Error> {
508        WatcherEvent::decode(self.client.wait_for_event(deadline)?)
509    }
510
511    /// Returns crashes as they occur. Each subsequent call will return a new crash.
512    pub fn r#get_crash(
513        &self,
514        mut payload: &WatcherGetCrashRequest,
515        ___deadline: zx::MonotonicInstant,
516    ) -> Result<WatcherGetCrashResult, fidl::Error> {
517        let _response = self
518            .client
519            .send_query::<WatcherGetCrashRequest, fidl::encoding::FlexibleResultType<Crash, Error>>(
520                payload,
521                0x3958bce1352d0890,
522                fidl::encoding::DynamicFlags::FLEXIBLE,
523                ___deadline,
524            )?
525            .into_result::<WatcherMarker>("get_crash")?;
526        Ok(_response.map(|x| x))
527    }
528
529    /// Returns an event which is has `ZX_USER_SIGNAL_0` asserted when a new crash is available.
530    pub fn r#get_crash_event(
531        &self,
532        ___deadline: zx::MonotonicInstant,
533    ) -> Result<fidl::EventPair, fidl::Error> {
534        let _response = self.client.send_query::<
535            fidl::encoding::EmptyPayload,
536            fidl::encoding::FlexibleType<WatcherGetCrashEventResponse>,
537        >(
538            (),
539            0x7105bc7fa9488070,
540            fidl::encoding::DynamicFlags::FLEXIBLE,
541            ___deadline,
542        )?
543        .into_result::<WatcherMarker>("get_crash_event")?;
544        Ok(_response.event)
545    }
546}
547
548#[cfg(target_os = "fuchsia")]
549impl From<WatcherSynchronousProxy> for zx::NullableHandle {
550    fn from(value: WatcherSynchronousProxy) -> Self {
551        value.into_channel().into()
552    }
553}
554
555#[cfg(target_os = "fuchsia")]
556impl From<fidl::Channel> for WatcherSynchronousProxy {
557    fn from(value: fidl::Channel) -> Self {
558        Self::new(value)
559    }
560}
561
562#[cfg(target_os = "fuchsia")]
563impl fidl::endpoints::FromClient for WatcherSynchronousProxy {
564    type Protocol = WatcherMarker;
565
566    fn from_client(value: fidl::endpoints::ClientEnd<WatcherMarker>) -> Self {
567        Self::new(value.into_channel())
568    }
569}
570
571#[derive(Debug, Clone)]
572pub struct WatcherProxy {
573    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
574}
575
576impl fidl::endpoints::Proxy for WatcherProxy {
577    type Protocol = WatcherMarker;
578
579    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
580        Self::new(inner)
581    }
582
583    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
584        self.client.into_channel().map_err(|client| Self { client })
585    }
586
587    fn as_channel(&self) -> &::fidl::AsyncChannel {
588        self.client.as_channel()
589    }
590}
591
592impl WatcherProxy {
593    /// Create a new Proxy for fuchsia.firmware.crash/Watcher.
594    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
595        let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
596        Self { client: fidl::client::Client::new(channel, protocol_name) }
597    }
598
599    /// Get a Stream of events from the remote end of the protocol.
600    ///
601    /// # Panics
602    ///
603    /// Panics if the event stream was already taken.
604    pub fn take_event_stream(&self) -> WatcherEventStream {
605        WatcherEventStream { event_receiver: self.client.take_event_receiver() }
606    }
607
608    /// Returns crashes as they occur. Each subsequent call will return a new crash.
609    pub fn r#get_crash(
610        &self,
611        mut payload: &WatcherGetCrashRequest,
612    ) -> fidl::client::QueryResponseFut<
613        WatcherGetCrashResult,
614        fidl::encoding::DefaultFuchsiaResourceDialect,
615    > {
616        WatcherProxyInterface::r#get_crash(self, payload)
617    }
618
619    /// Returns an event which is has `ZX_USER_SIGNAL_0` asserted when a new crash is available.
620    pub fn r#get_crash_event(
621        &self,
622    ) -> fidl::client::QueryResponseFut<
623        fidl::EventPair,
624        fidl::encoding::DefaultFuchsiaResourceDialect,
625    > {
626        WatcherProxyInterface::r#get_crash_event(self)
627    }
628}
629
630impl WatcherProxyInterface for WatcherProxy {
631    type GetCrashResponseFut = fidl::client::QueryResponseFut<
632        WatcherGetCrashResult,
633        fidl::encoding::DefaultFuchsiaResourceDialect,
634    >;
635    fn r#get_crash(&self, mut payload: &WatcherGetCrashRequest) -> Self::GetCrashResponseFut {
636        fn _decode(
637            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
638        ) -> Result<WatcherGetCrashResult, fidl::Error> {
639            let _response = fidl::client::decode_transaction_body::<
640                fidl::encoding::FlexibleResultType<Crash, Error>,
641                fidl::encoding::DefaultFuchsiaResourceDialect,
642                0x3958bce1352d0890,
643            >(_buf?)?
644            .into_result::<WatcherMarker>("get_crash")?;
645            Ok(_response.map(|x| x))
646        }
647        self.client.send_query_and_decode::<WatcherGetCrashRequest, WatcherGetCrashResult>(
648            payload,
649            0x3958bce1352d0890,
650            fidl::encoding::DynamicFlags::FLEXIBLE,
651            _decode,
652        )
653    }
654
655    type GetCrashEventResponseFut = fidl::client::QueryResponseFut<
656        fidl::EventPair,
657        fidl::encoding::DefaultFuchsiaResourceDialect,
658    >;
659    fn r#get_crash_event(&self) -> Self::GetCrashEventResponseFut {
660        fn _decode(
661            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
662        ) -> Result<fidl::EventPair, fidl::Error> {
663            let _response = fidl::client::decode_transaction_body::<
664                fidl::encoding::FlexibleType<WatcherGetCrashEventResponse>,
665                fidl::encoding::DefaultFuchsiaResourceDialect,
666                0x7105bc7fa9488070,
667            >(_buf?)?
668            .into_result::<WatcherMarker>("get_crash_event")?;
669            Ok(_response.event)
670        }
671        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, fidl::EventPair>(
672            (),
673            0x7105bc7fa9488070,
674            fidl::encoding::DynamicFlags::FLEXIBLE,
675            _decode,
676        )
677    }
678}
679
680pub struct WatcherEventStream {
681    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
682}
683
684impl std::marker::Unpin for WatcherEventStream {}
685
686impl futures::stream::FusedStream for WatcherEventStream {
687    fn is_terminated(&self) -> bool {
688        self.event_receiver.is_terminated()
689    }
690}
691
692impl futures::Stream for WatcherEventStream {
693    type Item = Result<WatcherEvent, fidl::Error>;
694
695    fn poll_next(
696        mut self: std::pin::Pin<&mut Self>,
697        cx: &mut std::task::Context<'_>,
698    ) -> std::task::Poll<Option<Self::Item>> {
699        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
700            &mut self.event_receiver,
701            cx
702        )?) {
703            Some(buf) => std::task::Poll::Ready(Some(WatcherEvent::decode(buf))),
704            None => std::task::Poll::Ready(None),
705        }
706    }
707}
708
709#[derive(Debug)]
710pub enum WatcherEvent {
711    #[non_exhaustive]
712    _UnknownEvent {
713        /// Ordinal of the event that was sent.
714        ordinal: u64,
715    },
716}
717
718impl WatcherEvent {
719    /// Decodes a message buffer as a [`WatcherEvent`].
720    fn decode(
721        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
722    ) -> Result<WatcherEvent, fidl::Error> {
723        let (bytes, _handles) = buf.split_mut();
724        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
725        debug_assert_eq!(tx_header.tx_id, 0);
726        match tx_header.ordinal {
727            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
728                Ok(WatcherEvent::_UnknownEvent { ordinal: tx_header.ordinal })
729            }
730            _ => Err(fidl::Error::UnknownOrdinal {
731                ordinal: tx_header.ordinal,
732                protocol_name: <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
733            }),
734        }
735    }
736}
737
738/// A Stream of incoming requests for fuchsia.firmware.crash/Watcher.
739pub struct WatcherRequestStream {
740    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
741    is_terminated: bool,
742}
743
744impl std::marker::Unpin for WatcherRequestStream {}
745
746impl futures::stream::FusedStream for WatcherRequestStream {
747    fn is_terminated(&self) -> bool {
748        self.is_terminated
749    }
750}
751
752impl fidl::endpoints::RequestStream for WatcherRequestStream {
753    type Protocol = WatcherMarker;
754    type ControlHandle = WatcherControlHandle;
755
756    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
757        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
758    }
759
760    fn control_handle(&self) -> Self::ControlHandle {
761        WatcherControlHandle { inner: self.inner.clone() }
762    }
763
764    fn into_inner(
765        self,
766    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
767    {
768        (self.inner, self.is_terminated)
769    }
770
771    fn from_inner(
772        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
773        is_terminated: bool,
774    ) -> Self {
775        Self { inner, is_terminated }
776    }
777}
778
779impl futures::Stream for WatcherRequestStream {
780    type Item = Result<WatcherRequest, fidl::Error>;
781
782    fn poll_next(
783        mut self: std::pin::Pin<&mut Self>,
784        cx: &mut std::task::Context<'_>,
785    ) -> std::task::Poll<Option<Self::Item>> {
786        let this = &mut *self;
787        if this.inner.check_shutdown(cx) {
788            this.is_terminated = true;
789            return std::task::Poll::Ready(None);
790        }
791        if this.is_terminated {
792            panic!("polled WatcherRequestStream after completion");
793        }
794        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
795            |bytes, handles| {
796                match this.inner.channel().read_etc(cx, bytes, handles) {
797                    std::task::Poll::Ready(Ok(())) => {}
798                    std::task::Poll::Pending => return std::task::Poll::Pending,
799                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
800                        this.is_terminated = true;
801                        return std::task::Poll::Ready(None);
802                    }
803                    std::task::Poll::Ready(Err(e)) => {
804                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
805                            e.into(),
806                        ))));
807                    }
808                }
809
810                // A message has been received from the channel
811                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
812
813                std::task::Poll::Ready(Some(match header.ordinal {
814                    0x3958bce1352d0890 => {
815                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
816                        let mut req = fidl::new_empty!(
817                            WatcherGetCrashRequest,
818                            fidl::encoding::DefaultFuchsiaResourceDialect
819                        );
820                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<WatcherGetCrashRequest>(&header, _body_bytes, handles, &mut req)?;
821                        let control_handle = WatcherControlHandle { inner: this.inner.clone() };
822                        Ok(WatcherRequest::GetCrash {
823                            payload: req,
824                            responder: WatcherGetCrashResponder {
825                                control_handle: std::mem::ManuallyDrop::new(control_handle),
826                                tx_id: header.tx_id,
827                            },
828                        })
829                    }
830                    0x7105bc7fa9488070 => {
831                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
832                        let mut req = fidl::new_empty!(
833                            fidl::encoding::EmptyPayload,
834                            fidl::encoding::DefaultFuchsiaResourceDialect
835                        );
836                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
837                        let control_handle = WatcherControlHandle { inner: this.inner.clone() };
838                        Ok(WatcherRequest::GetCrashEvent {
839                            responder: WatcherGetCrashEventResponder {
840                                control_handle: std::mem::ManuallyDrop::new(control_handle),
841                                tx_id: header.tx_id,
842                            },
843                        })
844                    }
845                    _ if header.tx_id == 0
846                        && header
847                            .dynamic_flags()
848                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
849                    {
850                        Ok(WatcherRequest::_UnknownMethod {
851                            ordinal: header.ordinal,
852                            control_handle: WatcherControlHandle { inner: this.inner.clone() },
853                            method_type: fidl::MethodType::OneWay,
854                        })
855                    }
856                    _ if header
857                        .dynamic_flags()
858                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
859                    {
860                        this.inner.send_framework_err(
861                            fidl::encoding::FrameworkErr::UnknownMethod,
862                            header.tx_id,
863                            header.ordinal,
864                            header.dynamic_flags(),
865                            (bytes, handles),
866                        )?;
867                        Ok(WatcherRequest::_UnknownMethod {
868                            ordinal: header.ordinal,
869                            control_handle: WatcherControlHandle { inner: this.inner.clone() },
870                            method_type: fidl::MethodType::TwoWay,
871                        })
872                    }
873                    _ => Err(fidl::Error::UnknownOrdinal {
874                        ordinal: header.ordinal,
875                        protocol_name:
876                            <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
877                    }),
878                }))
879            },
880        )
881    }
882}
883
884#[derive(Debug)]
885pub enum WatcherRequest {
886    /// Returns crashes as they occur. Each subsequent call will return a new crash.
887    GetCrash { payload: WatcherGetCrashRequest, responder: WatcherGetCrashResponder },
888    /// Returns an event which is has `ZX_USER_SIGNAL_0` asserted when a new crash is available.
889    GetCrashEvent { responder: WatcherGetCrashEventResponder },
890    /// An interaction was received which does not match any known method.
891    #[non_exhaustive]
892    _UnknownMethod {
893        /// Ordinal of the method that was called.
894        ordinal: u64,
895        control_handle: WatcherControlHandle,
896        method_type: fidl::MethodType,
897    },
898}
899
900impl WatcherRequest {
901    #[allow(irrefutable_let_patterns)]
902    pub fn into_get_crash(self) -> Option<(WatcherGetCrashRequest, WatcherGetCrashResponder)> {
903        if let WatcherRequest::GetCrash { payload, responder } = self {
904            Some((payload, responder))
905        } else {
906            None
907        }
908    }
909
910    #[allow(irrefutable_let_patterns)]
911    pub fn into_get_crash_event(self) -> Option<(WatcherGetCrashEventResponder)> {
912        if let WatcherRequest::GetCrashEvent { responder } = self {
913            Some((responder))
914        } else {
915            None
916        }
917    }
918
919    /// Name of the method defined in FIDL
920    pub fn method_name(&self) -> &'static str {
921        match *self {
922            WatcherRequest::GetCrash { .. } => "get_crash",
923            WatcherRequest::GetCrashEvent { .. } => "get_crash_event",
924            WatcherRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
925                "unknown one-way method"
926            }
927            WatcherRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
928                "unknown two-way method"
929            }
930        }
931    }
932}
933
934#[derive(Debug, Clone)]
935pub struct WatcherControlHandle {
936    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
937}
938
939impl fidl::endpoints::ControlHandle for WatcherControlHandle {
940    fn shutdown(&self) {
941        self.inner.shutdown()
942    }
943
944    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
945        self.inner.shutdown_with_epitaph(status)
946    }
947
948    fn is_closed(&self) -> bool {
949        self.inner.channel().is_closed()
950    }
951    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
952        self.inner.channel().on_closed()
953    }
954
955    #[cfg(target_os = "fuchsia")]
956    fn signal_peer(
957        &self,
958        clear_mask: zx::Signals,
959        set_mask: zx::Signals,
960    ) -> Result<(), zx_status::Status> {
961        use fidl::Peered;
962        self.inner.channel().signal_peer(clear_mask, set_mask)
963    }
964}
965
966impl WatcherControlHandle {}
967
968#[must_use = "FIDL methods require a response to be sent"]
969#[derive(Debug)]
970pub struct WatcherGetCrashResponder {
971    control_handle: std::mem::ManuallyDrop<WatcherControlHandle>,
972    tx_id: u32,
973}
974
975/// Set the the channel to be shutdown (see [`WatcherControlHandle::shutdown`])
976/// if the responder is dropped without sending a response, so that the client
977/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
978impl std::ops::Drop for WatcherGetCrashResponder {
979    fn drop(&mut self) {
980        self.control_handle.shutdown();
981        // Safety: drops once, never accessed again
982        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
983    }
984}
985
986impl fidl::endpoints::Responder for WatcherGetCrashResponder {
987    type ControlHandle = WatcherControlHandle;
988
989    fn control_handle(&self) -> &WatcherControlHandle {
990        &self.control_handle
991    }
992
993    fn drop_without_shutdown(mut self) {
994        // Safety: drops once, never accessed again due to mem::forget
995        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
996        // Prevent Drop from running (which would shut down the channel)
997        std::mem::forget(self);
998    }
999}
1000
1001impl WatcherGetCrashResponder {
1002    /// Sends a response to the FIDL transaction.
1003    ///
1004    /// Sets the channel to shutdown if an error occurs.
1005    pub fn send(self, mut result: Result<Crash, Error>) -> Result<(), fidl::Error> {
1006        let _result = self.send_raw(result);
1007        if _result.is_err() {
1008            self.control_handle.shutdown();
1009        }
1010        self.drop_without_shutdown();
1011        _result
1012    }
1013
1014    /// Similar to "send" but does not shutdown the channel if an error occurs.
1015    pub fn send_no_shutdown_on_err(
1016        self,
1017        mut result: Result<Crash, Error>,
1018    ) -> Result<(), fidl::Error> {
1019        let _result = self.send_raw(result);
1020        self.drop_without_shutdown();
1021        _result
1022    }
1023
1024    fn send_raw(&self, mut result: Result<Crash, Error>) -> Result<(), fidl::Error> {
1025        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<Crash, Error>>(
1026            fidl::encoding::FlexibleResult::new(result.as_mut().map_err(|e| *e)),
1027            self.tx_id,
1028            0x3958bce1352d0890,
1029            fidl::encoding::DynamicFlags::FLEXIBLE,
1030        )
1031    }
1032}
1033
1034#[must_use = "FIDL methods require a response to be sent"]
1035#[derive(Debug)]
1036pub struct WatcherGetCrashEventResponder {
1037    control_handle: std::mem::ManuallyDrop<WatcherControlHandle>,
1038    tx_id: u32,
1039}
1040
1041/// Set the the channel to be shutdown (see [`WatcherControlHandle::shutdown`])
1042/// if the responder is dropped without sending a response, so that the client
1043/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1044impl std::ops::Drop for WatcherGetCrashEventResponder {
1045    fn drop(&mut self) {
1046        self.control_handle.shutdown();
1047        // Safety: drops once, never accessed again
1048        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1049    }
1050}
1051
1052impl fidl::endpoints::Responder for WatcherGetCrashEventResponder {
1053    type ControlHandle = WatcherControlHandle;
1054
1055    fn control_handle(&self) -> &WatcherControlHandle {
1056        &self.control_handle
1057    }
1058
1059    fn drop_without_shutdown(mut self) {
1060        // Safety: drops once, never accessed again due to mem::forget
1061        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1062        // Prevent Drop from running (which would shut down the channel)
1063        std::mem::forget(self);
1064    }
1065}
1066
1067impl WatcherGetCrashEventResponder {
1068    /// Sends a response to the FIDL transaction.
1069    ///
1070    /// Sets the channel to shutdown if an error occurs.
1071    pub fn send(self, mut event: fidl::EventPair) -> Result<(), fidl::Error> {
1072        let _result = self.send_raw(event);
1073        if _result.is_err() {
1074            self.control_handle.shutdown();
1075        }
1076        self.drop_without_shutdown();
1077        _result
1078    }
1079
1080    /// Similar to "send" but does not shutdown the channel if an error occurs.
1081    pub fn send_no_shutdown_on_err(self, mut event: fidl::EventPair) -> Result<(), fidl::Error> {
1082        let _result = self.send_raw(event);
1083        self.drop_without_shutdown();
1084        _result
1085    }
1086
1087    fn send_raw(&self, mut event: fidl::EventPair) -> Result<(), fidl::Error> {
1088        self.control_handle
1089            .inner
1090            .send::<fidl::encoding::FlexibleType<WatcherGetCrashEventResponse>>(
1091                fidl::encoding::Flexible::new((event,)),
1092                self.tx_id,
1093                0x7105bc7fa9488070,
1094                fidl::encoding::DynamicFlags::FLEXIBLE,
1095            )
1096    }
1097}
1098
1099mod internal {
1100    use super::*;
1101
1102    impl fidl::encoding::ResourceTypeMarker for WatcherGetCrashEventResponse {
1103        type Borrowed<'a> = &'a mut Self;
1104        fn take_or_borrow<'a>(
1105            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1106        ) -> Self::Borrowed<'a> {
1107            value
1108        }
1109    }
1110
1111    unsafe impl fidl::encoding::TypeMarker for WatcherGetCrashEventResponse {
1112        type Owned = Self;
1113
1114        #[inline(always)]
1115        fn inline_align(_context: fidl::encoding::Context) -> usize {
1116            4
1117        }
1118
1119        #[inline(always)]
1120        fn inline_size(_context: fidl::encoding::Context) -> usize {
1121            4
1122        }
1123    }
1124
1125    unsafe impl
1126        fidl::encoding::Encode<
1127            WatcherGetCrashEventResponse,
1128            fidl::encoding::DefaultFuchsiaResourceDialect,
1129        > for &mut WatcherGetCrashEventResponse
1130    {
1131        #[inline]
1132        unsafe fn encode(
1133            self,
1134            encoder: &mut fidl::encoding::Encoder<
1135                '_,
1136                fidl::encoding::DefaultFuchsiaResourceDialect,
1137            >,
1138            offset: usize,
1139            _depth: fidl::encoding::Depth,
1140        ) -> fidl::Result<()> {
1141            encoder.debug_check_bounds::<WatcherGetCrashEventResponse>(offset);
1142            // Delegate to tuple encoding.
1143            fidl::encoding::Encode::<
1144                WatcherGetCrashEventResponse,
1145                fidl::encoding::DefaultFuchsiaResourceDialect,
1146            >::encode(
1147                (<fidl::encoding::HandleType<
1148                    fidl::EventPair,
1149                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1150                    2147483648,
1151                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1152                    &mut self.event
1153                ),),
1154                encoder,
1155                offset,
1156                _depth,
1157            )
1158        }
1159    }
1160    unsafe impl<
1161        T0: fidl::encoding::Encode<
1162                fidl::encoding::HandleType<
1163                    fidl::EventPair,
1164                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1165                    2147483648,
1166                >,
1167                fidl::encoding::DefaultFuchsiaResourceDialect,
1168            >,
1169    >
1170        fidl::encoding::Encode<
1171            WatcherGetCrashEventResponse,
1172            fidl::encoding::DefaultFuchsiaResourceDialect,
1173        > for (T0,)
1174    {
1175        #[inline]
1176        unsafe fn encode(
1177            self,
1178            encoder: &mut fidl::encoding::Encoder<
1179                '_,
1180                fidl::encoding::DefaultFuchsiaResourceDialect,
1181            >,
1182            offset: usize,
1183            depth: fidl::encoding::Depth,
1184        ) -> fidl::Result<()> {
1185            encoder.debug_check_bounds::<WatcherGetCrashEventResponse>(offset);
1186            // Zero out padding regions. There's no need to apply masks
1187            // because the unmasked parts will be overwritten by fields.
1188            // Write the fields.
1189            self.0.encode(encoder, offset + 0, depth)?;
1190            Ok(())
1191        }
1192    }
1193
1194    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1195        for WatcherGetCrashEventResponse
1196    {
1197        #[inline(always)]
1198        fn new_empty() -> Self {
1199            Self {
1200                event: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
1201            }
1202        }
1203
1204        #[inline]
1205        unsafe fn decode(
1206            &mut self,
1207            decoder: &mut fidl::encoding::Decoder<
1208                '_,
1209                fidl::encoding::DefaultFuchsiaResourceDialect,
1210            >,
1211            offset: usize,
1212            _depth: fidl::encoding::Depth,
1213        ) -> fidl::Result<()> {
1214            decoder.debug_check_bounds::<Self>(offset);
1215            // Verify that padding bytes are zero.
1216            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.event, decoder, offset + 0, _depth)?;
1217            Ok(())
1218        }
1219    }
1220
1221    impl Crash {
1222        #[inline(always)]
1223        fn max_ordinal_present(&self) -> u64 {
1224            if let Some(_) = self.crash_dump {
1225                return 6;
1226            }
1227            if let Some(_) = self.firmware_version {
1228                return 5;
1229            }
1230            if let Some(_) = self.count {
1231                return 4;
1232            }
1233            if let Some(_) = self.reason {
1234                return 3;
1235            }
1236            if let Some(_) = self.timestamp {
1237                return 2;
1238            }
1239            if let Some(_) = self.subsystem_name {
1240                return 1;
1241            }
1242            0
1243        }
1244    }
1245
1246    impl fidl::encoding::ResourceTypeMarker for Crash {
1247        type Borrowed<'a> = &'a mut Self;
1248        fn take_or_borrow<'a>(
1249            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1250        ) -> Self::Borrowed<'a> {
1251            value
1252        }
1253    }
1254
1255    unsafe impl fidl::encoding::TypeMarker for Crash {
1256        type Owned = Self;
1257
1258        #[inline(always)]
1259        fn inline_align(_context: fidl::encoding::Context) -> usize {
1260            8
1261        }
1262
1263        #[inline(always)]
1264        fn inline_size(_context: fidl::encoding::Context) -> usize {
1265            16
1266        }
1267    }
1268
1269    unsafe impl fidl::encoding::Encode<Crash, fidl::encoding::DefaultFuchsiaResourceDialect>
1270        for &mut Crash
1271    {
1272        unsafe fn encode(
1273            self,
1274            encoder: &mut fidl::encoding::Encoder<
1275                '_,
1276                fidl::encoding::DefaultFuchsiaResourceDialect,
1277            >,
1278            offset: usize,
1279            mut depth: fidl::encoding::Depth,
1280        ) -> fidl::Result<()> {
1281            encoder.debug_check_bounds::<Crash>(offset);
1282            // Vector header
1283            let max_ordinal: u64 = self.max_ordinal_present();
1284            encoder.write_num(max_ordinal, offset);
1285            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1286            // Calling encoder.out_of_line_offset(0) is not allowed.
1287            if max_ordinal == 0 {
1288                return Ok(());
1289            }
1290            depth.increment()?;
1291            let envelope_size = 8;
1292            let bytes_len = max_ordinal as usize * envelope_size;
1293            #[allow(unused_variables)]
1294            let offset = encoder.out_of_line_offset(bytes_len);
1295            let mut _prev_end_offset: usize = 0;
1296            if 1 > max_ordinal {
1297                return Ok(());
1298            }
1299
1300            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1301            // are envelope_size bytes.
1302            let cur_offset: usize = (1 - 1) * envelope_size;
1303
1304            // Zero reserved fields.
1305            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1306
1307            // Safety:
1308            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1309            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1310            //   envelope_size bytes, there is always sufficient room.
1311            fidl::encoding::encode_in_envelope_optional::<
1312                fidl::encoding::BoundedString<64>,
1313                fidl::encoding::DefaultFuchsiaResourceDialect,
1314            >(
1315                self.subsystem_name.as_ref().map(
1316                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow,
1317                ),
1318                encoder,
1319                offset + cur_offset,
1320                depth,
1321            )?;
1322
1323            _prev_end_offset = cur_offset + envelope_size;
1324            if 2 > max_ordinal {
1325                return Ok(());
1326            }
1327
1328            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1329            // are envelope_size bytes.
1330            let cur_offset: usize = (2 - 1) * envelope_size;
1331
1332            // Zero reserved fields.
1333            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1334
1335            // Safety:
1336            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1337            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1338            //   envelope_size bytes, there is always sufficient room.
1339            fidl::encoding::encode_in_envelope_optional::<
1340                fidl::BootInstant,
1341                fidl::encoding::DefaultFuchsiaResourceDialect,
1342            >(
1343                self.timestamp
1344                    .as_ref()
1345                    .map(<fidl::BootInstant as fidl::encoding::ValueTypeMarker>::borrow),
1346                encoder,
1347                offset + cur_offset,
1348                depth,
1349            )?;
1350
1351            _prev_end_offset = cur_offset + envelope_size;
1352            if 3 > max_ordinal {
1353                return Ok(());
1354            }
1355
1356            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1357            // are envelope_size bytes.
1358            let cur_offset: usize = (3 - 1) * envelope_size;
1359
1360            // Zero reserved fields.
1361            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1362
1363            // Safety:
1364            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1365            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1366            //   envelope_size bytes, there is always sufficient room.
1367            fidl::encoding::encode_in_envelope_optional::<
1368                fidl::encoding::BoundedString<128>,
1369                fidl::encoding::DefaultFuchsiaResourceDialect,
1370            >(
1371                self.reason.as_ref().map(
1372                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow,
1373                ),
1374                encoder,
1375                offset + cur_offset,
1376                depth,
1377            )?;
1378
1379            _prev_end_offset = cur_offset + envelope_size;
1380            if 4 > max_ordinal {
1381                return Ok(());
1382            }
1383
1384            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1385            // are envelope_size bytes.
1386            let cur_offset: usize = (4 - 1) * envelope_size;
1387
1388            // Zero reserved fields.
1389            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1390
1391            // Safety:
1392            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1393            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1394            //   envelope_size bytes, there is always sufficient room.
1395            fidl::encoding::encode_in_envelope_optional::<
1396                u32,
1397                fidl::encoding::DefaultFuchsiaResourceDialect,
1398            >(
1399                self.count.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1400                encoder,
1401                offset + cur_offset,
1402                depth,
1403            )?;
1404
1405            _prev_end_offset = cur_offset + envelope_size;
1406            if 5 > max_ordinal {
1407                return Ok(());
1408            }
1409
1410            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1411            // are envelope_size bytes.
1412            let cur_offset: usize = (5 - 1) * envelope_size;
1413
1414            // Zero reserved fields.
1415            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1416
1417            // Safety:
1418            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1419            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1420            //   envelope_size bytes, there is always sufficient room.
1421            fidl::encoding::encode_in_envelope_optional::<
1422                fidl::encoding::BoundedString<32>,
1423                fidl::encoding::DefaultFuchsiaResourceDialect,
1424            >(
1425                self.firmware_version.as_ref().map(
1426                    <fidl::encoding::BoundedString<32> as fidl::encoding::ValueTypeMarker>::borrow,
1427                ),
1428                encoder,
1429                offset + cur_offset,
1430                depth,
1431            )?;
1432
1433            _prev_end_offset = cur_offset + envelope_size;
1434            if 6 > max_ordinal {
1435                return Ok(());
1436            }
1437
1438            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1439            // are envelope_size bytes.
1440            let cur_offset: usize = (6 - 1) * envelope_size;
1441
1442            // Zero reserved fields.
1443            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1444
1445            // Safety:
1446            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1447            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1448            //   envelope_size bytes, there is always sufficient room.
1449            fidl::encoding::encode_in_envelope_optional::<
1450                fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>,
1451                fidl::encoding::DefaultFuchsiaResourceDialect,
1452            >(
1453                self.crash_dump.as_mut().map(
1454                    <fidl::encoding::HandleType<
1455                        fidl::Vmo,
1456                        { fidl::ObjectType::VMO.into_raw() },
1457                        49255,
1458                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
1459                ),
1460                encoder,
1461                offset + cur_offset,
1462                depth,
1463            )?;
1464
1465            _prev_end_offset = cur_offset + envelope_size;
1466
1467            Ok(())
1468        }
1469    }
1470
1471    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Crash {
1472        #[inline(always)]
1473        fn new_empty() -> Self {
1474            Self::default()
1475        }
1476
1477        unsafe fn decode(
1478            &mut self,
1479            decoder: &mut fidl::encoding::Decoder<
1480                '_,
1481                fidl::encoding::DefaultFuchsiaResourceDialect,
1482            >,
1483            offset: usize,
1484            mut depth: fidl::encoding::Depth,
1485        ) -> fidl::Result<()> {
1486            decoder.debug_check_bounds::<Self>(offset);
1487            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1488                None => return Err(fidl::Error::NotNullable),
1489                Some(len) => len,
1490            };
1491            // Calling decoder.out_of_line_offset(0) is not allowed.
1492            if len == 0 {
1493                return Ok(());
1494            };
1495            depth.increment()?;
1496            let envelope_size = 8;
1497            let bytes_len = len * envelope_size;
1498            let offset = decoder.out_of_line_offset(bytes_len)?;
1499            // Decode the envelope for each type.
1500            let mut _next_ordinal_to_read = 0;
1501            let mut next_offset = offset;
1502            let end_offset = offset + bytes_len;
1503            _next_ordinal_to_read += 1;
1504            if next_offset >= end_offset {
1505                return Ok(());
1506            }
1507
1508            // Decode unknown envelopes for gaps in ordinals.
1509            while _next_ordinal_to_read < 1 {
1510                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1511                _next_ordinal_to_read += 1;
1512                next_offset += envelope_size;
1513            }
1514
1515            let next_out_of_line = decoder.next_out_of_line();
1516            let handles_before = decoder.remaining_handles();
1517            if let Some((inlined, num_bytes, num_handles)) =
1518                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1519            {
1520                let member_inline_size =
1521                    <fidl::encoding::BoundedString<64> as fidl::encoding::TypeMarker>::inline_size(
1522                        decoder.context,
1523                    );
1524                if inlined != (member_inline_size <= 4) {
1525                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1526                }
1527                let inner_offset;
1528                let mut inner_depth = depth.clone();
1529                if inlined {
1530                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1531                    inner_offset = next_offset;
1532                } else {
1533                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1534                    inner_depth.increment()?;
1535                }
1536                let val_ref = self.subsystem_name.get_or_insert_with(|| {
1537                    fidl::new_empty!(
1538                        fidl::encoding::BoundedString<64>,
1539                        fidl::encoding::DefaultFuchsiaResourceDialect
1540                    )
1541                });
1542                fidl::decode!(
1543                    fidl::encoding::BoundedString<64>,
1544                    fidl::encoding::DefaultFuchsiaResourceDialect,
1545                    val_ref,
1546                    decoder,
1547                    inner_offset,
1548                    inner_depth
1549                )?;
1550                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1551                {
1552                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1553                }
1554                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1555                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1556                }
1557            }
1558
1559            next_offset += envelope_size;
1560            _next_ordinal_to_read += 1;
1561            if next_offset >= end_offset {
1562                return Ok(());
1563            }
1564
1565            // Decode unknown envelopes for gaps in ordinals.
1566            while _next_ordinal_to_read < 2 {
1567                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1568                _next_ordinal_to_read += 1;
1569                next_offset += envelope_size;
1570            }
1571
1572            let next_out_of_line = decoder.next_out_of_line();
1573            let handles_before = decoder.remaining_handles();
1574            if let Some((inlined, num_bytes, num_handles)) =
1575                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1576            {
1577                let member_inline_size =
1578                    <fidl::BootInstant as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1579                if inlined != (member_inline_size <= 4) {
1580                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1581                }
1582                let inner_offset;
1583                let mut inner_depth = depth.clone();
1584                if inlined {
1585                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1586                    inner_offset = next_offset;
1587                } else {
1588                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1589                    inner_depth.increment()?;
1590                }
1591                let val_ref = self.timestamp.get_or_insert_with(|| {
1592                    fidl::new_empty!(
1593                        fidl::BootInstant,
1594                        fidl::encoding::DefaultFuchsiaResourceDialect
1595                    )
1596                });
1597                fidl::decode!(
1598                    fidl::BootInstant,
1599                    fidl::encoding::DefaultFuchsiaResourceDialect,
1600                    val_ref,
1601                    decoder,
1602                    inner_offset,
1603                    inner_depth
1604                )?;
1605                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1606                {
1607                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1608                }
1609                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1610                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1611                }
1612            }
1613
1614            next_offset += envelope_size;
1615            _next_ordinal_to_read += 1;
1616            if next_offset >= end_offset {
1617                return Ok(());
1618            }
1619
1620            // Decode unknown envelopes for gaps in ordinals.
1621            while _next_ordinal_to_read < 3 {
1622                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1623                _next_ordinal_to_read += 1;
1624                next_offset += envelope_size;
1625            }
1626
1627            let next_out_of_line = decoder.next_out_of_line();
1628            let handles_before = decoder.remaining_handles();
1629            if let Some((inlined, num_bytes, num_handles)) =
1630                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1631            {
1632                let member_inline_size =
1633                    <fidl::encoding::BoundedString<128> as fidl::encoding::TypeMarker>::inline_size(
1634                        decoder.context,
1635                    );
1636                if inlined != (member_inline_size <= 4) {
1637                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1638                }
1639                let inner_offset;
1640                let mut inner_depth = depth.clone();
1641                if inlined {
1642                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1643                    inner_offset = next_offset;
1644                } else {
1645                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1646                    inner_depth.increment()?;
1647                }
1648                let val_ref = self.reason.get_or_insert_with(|| {
1649                    fidl::new_empty!(
1650                        fidl::encoding::BoundedString<128>,
1651                        fidl::encoding::DefaultFuchsiaResourceDialect
1652                    )
1653                });
1654                fidl::decode!(
1655                    fidl::encoding::BoundedString<128>,
1656                    fidl::encoding::DefaultFuchsiaResourceDialect,
1657                    val_ref,
1658                    decoder,
1659                    inner_offset,
1660                    inner_depth
1661                )?;
1662                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1663                {
1664                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1665                }
1666                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1667                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1668                }
1669            }
1670
1671            next_offset += envelope_size;
1672            _next_ordinal_to_read += 1;
1673            if next_offset >= end_offset {
1674                return Ok(());
1675            }
1676
1677            // Decode unknown envelopes for gaps in ordinals.
1678            while _next_ordinal_to_read < 4 {
1679                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1680                _next_ordinal_to_read += 1;
1681                next_offset += envelope_size;
1682            }
1683
1684            let next_out_of_line = decoder.next_out_of_line();
1685            let handles_before = decoder.remaining_handles();
1686            if let Some((inlined, num_bytes, num_handles)) =
1687                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1688            {
1689                let member_inline_size =
1690                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1691                if inlined != (member_inline_size <= 4) {
1692                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1693                }
1694                let inner_offset;
1695                let mut inner_depth = depth.clone();
1696                if inlined {
1697                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1698                    inner_offset = next_offset;
1699                } else {
1700                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1701                    inner_depth.increment()?;
1702                }
1703                let val_ref = self.count.get_or_insert_with(|| {
1704                    fidl::new_empty!(u32, fidl::encoding::DefaultFuchsiaResourceDialect)
1705                });
1706                fidl::decode!(
1707                    u32,
1708                    fidl::encoding::DefaultFuchsiaResourceDialect,
1709                    val_ref,
1710                    decoder,
1711                    inner_offset,
1712                    inner_depth
1713                )?;
1714                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1715                {
1716                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1717                }
1718                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1719                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1720                }
1721            }
1722
1723            next_offset += envelope_size;
1724            _next_ordinal_to_read += 1;
1725            if next_offset >= end_offset {
1726                return Ok(());
1727            }
1728
1729            // Decode unknown envelopes for gaps in ordinals.
1730            while _next_ordinal_to_read < 5 {
1731                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1732                _next_ordinal_to_read += 1;
1733                next_offset += envelope_size;
1734            }
1735
1736            let next_out_of_line = decoder.next_out_of_line();
1737            let handles_before = decoder.remaining_handles();
1738            if let Some((inlined, num_bytes, num_handles)) =
1739                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1740            {
1741                let member_inline_size =
1742                    <fidl::encoding::BoundedString<32> as fidl::encoding::TypeMarker>::inline_size(
1743                        decoder.context,
1744                    );
1745                if inlined != (member_inline_size <= 4) {
1746                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1747                }
1748                let inner_offset;
1749                let mut inner_depth = depth.clone();
1750                if inlined {
1751                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1752                    inner_offset = next_offset;
1753                } else {
1754                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1755                    inner_depth.increment()?;
1756                }
1757                let val_ref = self.firmware_version.get_or_insert_with(|| {
1758                    fidl::new_empty!(
1759                        fidl::encoding::BoundedString<32>,
1760                        fidl::encoding::DefaultFuchsiaResourceDialect
1761                    )
1762                });
1763                fidl::decode!(
1764                    fidl::encoding::BoundedString<32>,
1765                    fidl::encoding::DefaultFuchsiaResourceDialect,
1766                    val_ref,
1767                    decoder,
1768                    inner_offset,
1769                    inner_depth
1770                )?;
1771                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1772                {
1773                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1774                }
1775                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1776                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1777                }
1778            }
1779
1780            next_offset += envelope_size;
1781            _next_ordinal_to_read += 1;
1782            if next_offset >= end_offset {
1783                return Ok(());
1784            }
1785
1786            // Decode unknown envelopes for gaps in ordinals.
1787            while _next_ordinal_to_read < 6 {
1788                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1789                _next_ordinal_to_read += 1;
1790                next_offset += envelope_size;
1791            }
1792
1793            let next_out_of_line = decoder.next_out_of_line();
1794            let handles_before = decoder.remaining_handles();
1795            if let Some((inlined, num_bytes, num_handles)) =
1796                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1797            {
1798                let member_inline_size = <fidl::encoding::HandleType<
1799                    fidl::Vmo,
1800                    { fidl::ObjectType::VMO.into_raw() },
1801                    49255,
1802                > as fidl::encoding::TypeMarker>::inline_size(
1803                    decoder.context
1804                );
1805                if inlined != (member_inline_size <= 4) {
1806                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1807                }
1808                let inner_offset;
1809                let mut inner_depth = depth.clone();
1810                if inlined {
1811                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1812                    inner_offset = next_offset;
1813                } else {
1814                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1815                    inner_depth.increment()?;
1816                }
1817                let val_ref =
1818                self.crash_dump.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect));
1819                fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
1820                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1821                {
1822                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1823                }
1824                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1825                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1826                }
1827            }
1828
1829            next_offset += envelope_size;
1830
1831            // Decode the remaining unknown envelopes.
1832            while next_offset < end_offset {
1833                _next_ordinal_to_read += 1;
1834                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1835                next_offset += envelope_size;
1836            }
1837
1838            Ok(())
1839        }
1840    }
1841}