fidl_fuchsia_memory_heapdump_process/
fidl_fuchsia_memory_heapdump_process.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_memory_heapdump_process__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct RegistryRegisterV1Request {
16    pub process: fidl::Process,
17    pub allocations_vmo: fidl::Vmo,
18    pub resources_vmo: fidl::Vmo,
19    pub snapshot_sink: fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
20}
21
22impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RegistryRegisterV1Request {}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct SnapshotSinkV1StoreNamedSnapshotRequest {
26    pub snapshot_name: String,
27    pub allocations_vmo_snapshot: fidl::Vmo,
28}
29
30impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
31    for SnapshotSinkV1StoreNamedSnapshotRequest
32{
33}
34
35#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
36pub struct RegistryMarker;
37
38impl fidl::endpoints::ProtocolMarker for RegistryMarker {
39    type Proxy = RegistryProxy;
40    type RequestStream = RegistryRequestStream;
41    #[cfg(target_os = "fuchsia")]
42    type SynchronousProxy = RegistrySynchronousProxy;
43
44    const DEBUG_NAME: &'static str = "fuchsia.memory.heapdump.process.Registry";
45}
46impl fidl::endpoints::DiscoverableProtocolMarker for RegistryMarker {}
47
48pub trait RegistryProxyInterface: Send + Sync {
49    fn r#register_v1(
50        &self,
51        process: fidl::Process,
52        allocations_vmo: fidl::Vmo,
53        resources_vmo: fidl::Vmo,
54        snapshot_sink: fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
55    ) -> Result<(), fidl::Error>;
56}
57#[derive(Debug)]
58#[cfg(target_os = "fuchsia")]
59pub struct RegistrySynchronousProxy {
60    client: fidl::client::sync::Client,
61}
62
63#[cfg(target_os = "fuchsia")]
64impl fidl::endpoints::SynchronousProxy for RegistrySynchronousProxy {
65    type Proxy = RegistryProxy;
66    type Protocol = RegistryMarker;
67
68    fn from_channel(inner: fidl::Channel) -> Self {
69        Self::new(inner)
70    }
71
72    fn into_channel(self) -> fidl::Channel {
73        self.client.into_channel()
74    }
75
76    fn as_channel(&self) -> &fidl::Channel {
77        self.client.as_channel()
78    }
79}
80
81#[cfg(target_os = "fuchsia")]
82impl RegistrySynchronousProxy {
83    pub fn new(channel: fidl::Channel) -> Self {
84        let protocol_name = <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
85        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
86    }
87
88    pub fn into_channel(self) -> fidl::Channel {
89        self.client.into_channel()
90    }
91
92    /// Waits until an event arrives and returns it. It is safe for other
93    /// threads to make concurrent requests while waiting for an event.
94    pub fn wait_for_event(
95        &self,
96        deadline: zx::MonotonicInstant,
97    ) -> Result<RegistryEvent, fidl::Error> {
98        RegistryEvent::decode(self.client.wait_for_event(deadline)?)
99    }
100
101    /// Binds the given process to the registry and share the relevant resources.
102    pub fn r#register_v1(
103        &self,
104        mut process: fidl::Process,
105        mut allocations_vmo: fidl::Vmo,
106        mut resources_vmo: fidl::Vmo,
107        mut snapshot_sink: fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
108    ) -> Result<(), fidl::Error> {
109        self.client.send::<RegistryRegisterV1Request>(
110            (process, allocations_vmo, resources_vmo, snapshot_sink),
111            0x68626342c5d1afce,
112            fidl::encoding::DynamicFlags::empty(),
113        )
114    }
115}
116
117#[cfg(target_os = "fuchsia")]
118impl From<RegistrySynchronousProxy> for zx::Handle {
119    fn from(value: RegistrySynchronousProxy) -> Self {
120        value.into_channel().into()
121    }
122}
123
124#[cfg(target_os = "fuchsia")]
125impl From<fidl::Channel> for RegistrySynchronousProxy {
126    fn from(value: fidl::Channel) -> Self {
127        Self::new(value)
128    }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl fidl::endpoints::FromClient for RegistrySynchronousProxy {
133    type Protocol = RegistryMarker;
134
135    fn from_client(value: fidl::endpoints::ClientEnd<RegistryMarker>) -> Self {
136        Self::new(value.into_channel())
137    }
138}
139
140#[derive(Debug, Clone)]
141pub struct RegistryProxy {
142    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
143}
144
145impl fidl::endpoints::Proxy for RegistryProxy {
146    type Protocol = RegistryMarker;
147
148    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
149        Self::new(inner)
150    }
151
152    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
153        self.client.into_channel().map_err(|client| Self { client })
154    }
155
156    fn as_channel(&self) -> &::fidl::AsyncChannel {
157        self.client.as_channel()
158    }
159}
160
161impl RegistryProxy {
162    /// Create a new Proxy for fuchsia.memory.heapdump.process/Registry.
163    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
164        let protocol_name = <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
165        Self { client: fidl::client::Client::new(channel, protocol_name) }
166    }
167
168    /// Get a Stream of events from the remote end of the protocol.
169    ///
170    /// # Panics
171    ///
172    /// Panics if the event stream was already taken.
173    pub fn take_event_stream(&self) -> RegistryEventStream {
174        RegistryEventStream { event_receiver: self.client.take_event_receiver() }
175    }
176
177    /// Binds the given process to the registry and share the relevant resources.
178    pub fn r#register_v1(
179        &self,
180        mut process: fidl::Process,
181        mut allocations_vmo: fidl::Vmo,
182        mut resources_vmo: fidl::Vmo,
183        mut snapshot_sink: fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
184    ) -> Result<(), fidl::Error> {
185        RegistryProxyInterface::r#register_v1(
186            self,
187            process,
188            allocations_vmo,
189            resources_vmo,
190            snapshot_sink,
191        )
192    }
193}
194
195impl RegistryProxyInterface for RegistryProxy {
196    fn r#register_v1(
197        &self,
198        mut process: fidl::Process,
199        mut allocations_vmo: fidl::Vmo,
200        mut resources_vmo: fidl::Vmo,
201        mut snapshot_sink: fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
202    ) -> Result<(), fidl::Error> {
203        self.client.send::<RegistryRegisterV1Request>(
204            (process, allocations_vmo, resources_vmo, snapshot_sink),
205            0x68626342c5d1afce,
206            fidl::encoding::DynamicFlags::empty(),
207        )
208    }
209}
210
211pub struct RegistryEventStream {
212    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
213}
214
215impl std::marker::Unpin for RegistryEventStream {}
216
217impl futures::stream::FusedStream for RegistryEventStream {
218    fn is_terminated(&self) -> bool {
219        self.event_receiver.is_terminated()
220    }
221}
222
223impl futures::Stream for RegistryEventStream {
224    type Item = Result<RegistryEvent, fidl::Error>;
225
226    fn poll_next(
227        mut self: std::pin::Pin<&mut Self>,
228        cx: &mut std::task::Context<'_>,
229    ) -> std::task::Poll<Option<Self::Item>> {
230        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
231            &mut self.event_receiver,
232            cx
233        )?) {
234            Some(buf) => std::task::Poll::Ready(Some(RegistryEvent::decode(buf))),
235            None => std::task::Poll::Ready(None),
236        }
237    }
238}
239
240#[derive(Debug)]
241pub enum RegistryEvent {}
242
243impl RegistryEvent {
244    /// Decodes a message buffer as a [`RegistryEvent`].
245    fn decode(
246        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
247    ) -> Result<RegistryEvent, fidl::Error> {
248        let (bytes, _handles) = buf.split_mut();
249        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
250        debug_assert_eq!(tx_header.tx_id, 0);
251        match tx_header.ordinal {
252            _ => Err(fidl::Error::UnknownOrdinal {
253                ordinal: tx_header.ordinal,
254                protocol_name: <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
255            }),
256        }
257    }
258}
259
260/// A Stream of incoming requests for fuchsia.memory.heapdump.process/Registry.
261pub struct RegistryRequestStream {
262    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
263    is_terminated: bool,
264}
265
266impl std::marker::Unpin for RegistryRequestStream {}
267
268impl futures::stream::FusedStream for RegistryRequestStream {
269    fn is_terminated(&self) -> bool {
270        self.is_terminated
271    }
272}
273
274impl fidl::endpoints::RequestStream for RegistryRequestStream {
275    type Protocol = RegistryMarker;
276    type ControlHandle = RegistryControlHandle;
277
278    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
279        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
280    }
281
282    fn control_handle(&self) -> Self::ControlHandle {
283        RegistryControlHandle { inner: self.inner.clone() }
284    }
285
286    fn into_inner(
287        self,
288    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
289    {
290        (self.inner, self.is_terminated)
291    }
292
293    fn from_inner(
294        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
295        is_terminated: bool,
296    ) -> Self {
297        Self { inner, is_terminated }
298    }
299}
300
301impl futures::Stream for RegistryRequestStream {
302    type Item = Result<RegistryRequest, fidl::Error>;
303
304    fn poll_next(
305        mut self: std::pin::Pin<&mut Self>,
306        cx: &mut std::task::Context<'_>,
307    ) -> std::task::Poll<Option<Self::Item>> {
308        let this = &mut *self;
309        if this.inner.check_shutdown(cx) {
310            this.is_terminated = true;
311            return std::task::Poll::Ready(None);
312        }
313        if this.is_terminated {
314            panic!("polled RegistryRequestStream after completion");
315        }
316        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
317            |bytes, handles| {
318                match this.inner.channel().read_etc(cx, bytes, handles) {
319                    std::task::Poll::Ready(Ok(())) => {}
320                    std::task::Poll::Pending => return std::task::Poll::Pending,
321                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
322                        this.is_terminated = true;
323                        return std::task::Poll::Ready(None);
324                    }
325                    std::task::Poll::Ready(Err(e)) => {
326                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
327                            e.into(),
328                        ))))
329                    }
330                }
331
332                // A message has been received from the channel
333                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
334
335                std::task::Poll::Ready(Some(match header.ordinal {
336                    0x68626342c5d1afce => {
337                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
338                        let mut req = fidl::new_empty!(
339                            RegistryRegisterV1Request,
340                            fidl::encoding::DefaultFuchsiaResourceDialect
341                        );
342                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RegistryRegisterV1Request>(&header, _body_bytes, handles, &mut req)?;
343                        let control_handle = RegistryControlHandle { inner: this.inner.clone() };
344                        Ok(RegistryRequest::RegisterV1 {
345                            process: req.process,
346                            allocations_vmo: req.allocations_vmo,
347                            resources_vmo: req.resources_vmo,
348                            snapshot_sink: req.snapshot_sink,
349
350                            control_handle,
351                        })
352                    }
353                    _ => Err(fidl::Error::UnknownOrdinal {
354                        ordinal: header.ordinal,
355                        protocol_name:
356                            <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
357                    }),
358                }))
359            },
360        )
361    }
362}
363
364/// The Registry keeps track of all the instrumented processes that are running in the system.
365#[derive(Debug)]
366pub enum RegistryRequest {
367    /// Binds the given process to the registry and share the relevant resources.
368    RegisterV1 {
369        process: fidl::Process,
370        allocations_vmo: fidl::Vmo,
371        resources_vmo: fidl::Vmo,
372        snapshot_sink: fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
373        control_handle: RegistryControlHandle,
374    },
375}
376
377impl RegistryRequest {
378    #[allow(irrefutable_let_patterns)]
379    pub fn into_register_v1(
380        self,
381    ) -> Option<(
382        fidl::Process,
383        fidl::Vmo,
384        fidl::Vmo,
385        fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>,
386        RegistryControlHandle,
387    )> {
388        if let RegistryRequest::RegisterV1 {
389            process,
390            allocations_vmo,
391            resources_vmo,
392            snapshot_sink,
393            control_handle,
394        } = self
395        {
396            Some((process, allocations_vmo, resources_vmo, snapshot_sink, control_handle))
397        } else {
398            None
399        }
400    }
401
402    /// Name of the method defined in FIDL
403    pub fn method_name(&self) -> &'static str {
404        match *self {
405            RegistryRequest::RegisterV1 { .. } => "register_v1",
406        }
407    }
408}
409
410#[derive(Debug, Clone)]
411pub struct RegistryControlHandle {
412    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
413}
414
415impl fidl::endpoints::ControlHandle for RegistryControlHandle {
416    fn shutdown(&self) {
417        self.inner.shutdown()
418    }
419    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
420        self.inner.shutdown_with_epitaph(status)
421    }
422
423    fn is_closed(&self) -> bool {
424        self.inner.channel().is_closed()
425    }
426    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
427        self.inner.channel().on_closed()
428    }
429
430    #[cfg(target_os = "fuchsia")]
431    fn signal_peer(
432        &self,
433        clear_mask: zx::Signals,
434        set_mask: zx::Signals,
435    ) -> Result<(), zx_status::Status> {
436        use fidl::Peered;
437        self.inner.channel().signal_peer(clear_mask, set_mask)
438    }
439}
440
441impl RegistryControlHandle {}
442
443#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
444pub struct SnapshotSinkV1Marker;
445
446impl fidl::endpoints::ProtocolMarker for SnapshotSinkV1Marker {
447    type Proxy = SnapshotSinkV1Proxy;
448    type RequestStream = SnapshotSinkV1RequestStream;
449    #[cfg(target_os = "fuchsia")]
450    type SynchronousProxy = SnapshotSinkV1SynchronousProxy;
451
452    const DEBUG_NAME: &'static str = "(anonymous) SnapshotSinkV1";
453}
454
455pub trait SnapshotSinkV1ProxyInterface: Send + Sync {
456    fn r#store_named_snapshot(
457        &self,
458        snapshot_name: &str,
459        allocations_vmo_snapshot: fidl::Vmo,
460    ) -> Result<(), fidl::Error>;
461}
462#[derive(Debug)]
463#[cfg(target_os = "fuchsia")]
464pub struct SnapshotSinkV1SynchronousProxy {
465    client: fidl::client::sync::Client,
466}
467
468#[cfg(target_os = "fuchsia")]
469impl fidl::endpoints::SynchronousProxy for SnapshotSinkV1SynchronousProxy {
470    type Proxy = SnapshotSinkV1Proxy;
471    type Protocol = SnapshotSinkV1Marker;
472
473    fn from_channel(inner: fidl::Channel) -> Self {
474        Self::new(inner)
475    }
476
477    fn into_channel(self) -> fidl::Channel {
478        self.client.into_channel()
479    }
480
481    fn as_channel(&self) -> &fidl::Channel {
482        self.client.as_channel()
483    }
484}
485
486#[cfg(target_os = "fuchsia")]
487impl SnapshotSinkV1SynchronousProxy {
488    pub fn new(channel: fidl::Channel) -> Self {
489        let protocol_name = <SnapshotSinkV1Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
490        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
491    }
492
493    pub fn into_channel(self) -> fidl::Channel {
494        self.client.into_channel()
495    }
496
497    /// Waits until an event arrives and returns it. It is safe for other
498    /// threads to make concurrent requests while waiting for an event.
499    pub fn wait_for_event(
500        &self,
501        deadline: zx::MonotonicInstant,
502    ) -> Result<SnapshotSinkV1Event, fidl::Error> {
503        SnapshotSinkV1Event::decode(self.client.wait_for_event(deadline)?)
504    }
505
506    /// Asks the server to store a snapshot with the given name and the given allocations VMO.
507    ///
508    /// All the resources referenced by the given allocations VMO will be resolved using the
509    /// resources VMO that was shared by the process at registration time.
510    pub fn r#store_named_snapshot(
511        &self,
512        mut snapshot_name: &str,
513        mut allocations_vmo_snapshot: fidl::Vmo,
514    ) -> Result<(), fidl::Error> {
515        self.client.send::<SnapshotSinkV1StoreNamedSnapshotRequest>(
516            (snapshot_name, allocations_vmo_snapshot),
517            0x356eaec66aabbea5,
518            fidl::encoding::DynamicFlags::empty(),
519        )
520    }
521}
522
523#[cfg(target_os = "fuchsia")]
524impl From<SnapshotSinkV1SynchronousProxy> for zx::Handle {
525    fn from(value: SnapshotSinkV1SynchronousProxy) -> Self {
526        value.into_channel().into()
527    }
528}
529
530#[cfg(target_os = "fuchsia")]
531impl From<fidl::Channel> for SnapshotSinkV1SynchronousProxy {
532    fn from(value: fidl::Channel) -> Self {
533        Self::new(value)
534    }
535}
536
537#[cfg(target_os = "fuchsia")]
538impl fidl::endpoints::FromClient for SnapshotSinkV1SynchronousProxy {
539    type Protocol = SnapshotSinkV1Marker;
540
541    fn from_client(value: fidl::endpoints::ClientEnd<SnapshotSinkV1Marker>) -> Self {
542        Self::new(value.into_channel())
543    }
544}
545
546#[derive(Debug, Clone)]
547pub struct SnapshotSinkV1Proxy {
548    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
549}
550
551impl fidl::endpoints::Proxy for SnapshotSinkV1Proxy {
552    type Protocol = SnapshotSinkV1Marker;
553
554    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
555        Self::new(inner)
556    }
557
558    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
559        self.client.into_channel().map_err(|client| Self { client })
560    }
561
562    fn as_channel(&self) -> &::fidl::AsyncChannel {
563        self.client.as_channel()
564    }
565}
566
567impl SnapshotSinkV1Proxy {
568    /// Create a new Proxy for fuchsia.memory.heapdump.process/SnapshotSinkV1.
569    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
570        let protocol_name = <SnapshotSinkV1Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
571        Self { client: fidl::client::Client::new(channel, protocol_name) }
572    }
573
574    /// Get a Stream of events from the remote end of the protocol.
575    ///
576    /// # Panics
577    ///
578    /// Panics if the event stream was already taken.
579    pub fn take_event_stream(&self) -> SnapshotSinkV1EventStream {
580        SnapshotSinkV1EventStream { event_receiver: self.client.take_event_receiver() }
581    }
582
583    /// Asks the server to store a snapshot with the given name and the given allocations VMO.
584    ///
585    /// All the resources referenced by the given allocations VMO will be resolved using the
586    /// resources VMO that was shared by the process at registration time.
587    pub fn r#store_named_snapshot(
588        &self,
589        mut snapshot_name: &str,
590        mut allocations_vmo_snapshot: fidl::Vmo,
591    ) -> Result<(), fidl::Error> {
592        SnapshotSinkV1ProxyInterface::r#store_named_snapshot(
593            self,
594            snapshot_name,
595            allocations_vmo_snapshot,
596        )
597    }
598}
599
600impl SnapshotSinkV1ProxyInterface for SnapshotSinkV1Proxy {
601    fn r#store_named_snapshot(
602        &self,
603        mut snapshot_name: &str,
604        mut allocations_vmo_snapshot: fidl::Vmo,
605    ) -> Result<(), fidl::Error> {
606        self.client.send::<SnapshotSinkV1StoreNamedSnapshotRequest>(
607            (snapshot_name, allocations_vmo_snapshot),
608            0x356eaec66aabbea5,
609            fidl::encoding::DynamicFlags::empty(),
610        )
611    }
612}
613
614pub struct SnapshotSinkV1EventStream {
615    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
616}
617
618impl std::marker::Unpin for SnapshotSinkV1EventStream {}
619
620impl futures::stream::FusedStream for SnapshotSinkV1EventStream {
621    fn is_terminated(&self) -> bool {
622        self.event_receiver.is_terminated()
623    }
624}
625
626impl futures::Stream for SnapshotSinkV1EventStream {
627    type Item = Result<SnapshotSinkV1Event, fidl::Error>;
628
629    fn poll_next(
630        mut self: std::pin::Pin<&mut Self>,
631        cx: &mut std::task::Context<'_>,
632    ) -> std::task::Poll<Option<Self::Item>> {
633        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
634            &mut self.event_receiver,
635            cx
636        )?) {
637            Some(buf) => std::task::Poll::Ready(Some(SnapshotSinkV1Event::decode(buf))),
638            None => std::task::Poll::Ready(None),
639        }
640    }
641}
642
643#[derive(Debug)]
644pub enum SnapshotSinkV1Event {}
645
646impl SnapshotSinkV1Event {
647    /// Decodes a message buffer as a [`SnapshotSinkV1Event`].
648    fn decode(
649        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
650    ) -> Result<SnapshotSinkV1Event, fidl::Error> {
651        let (bytes, _handles) = buf.split_mut();
652        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
653        debug_assert_eq!(tx_header.tx_id, 0);
654        match tx_header.ordinal {
655            _ => Err(fidl::Error::UnknownOrdinal {
656                ordinal: tx_header.ordinal,
657                protocol_name:
658                    <SnapshotSinkV1Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
659            }),
660        }
661    }
662}
663
664/// A Stream of incoming requests for fuchsia.memory.heapdump.process/SnapshotSinkV1.
665pub struct SnapshotSinkV1RequestStream {
666    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
667    is_terminated: bool,
668}
669
670impl std::marker::Unpin for SnapshotSinkV1RequestStream {}
671
672impl futures::stream::FusedStream for SnapshotSinkV1RequestStream {
673    fn is_terminated(&self) -> bool {
674        self.is_terminated
675    }
676}
677
678impl fidl::endpoints::RequestStream for SnapshotSinkV1RequestStream {
679    type Protocol = SnapshotSinkV1Marker;
680    type ControlHandle = SnapshotSinkV1ControlHandle;
681
682    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
683        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
684    }
685
686    fn control_handle(&self) -> Self::ControlHandle {
687        SnapshotSinkV1ControlHandle { inner: self.inner.clone() }
688    }
689
690    fn into_inner(
691        self,
692    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
693    {
694        (self.inner, self.is_terminated)
695    }
696
697    fn from_inner(
698        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
699        is_terminated: bool,
700    ) -> Self {
701        Self { inner, is_terminated }
702    }
703}
704
705impl futures::Stream for SnapshotSinkV1RequestStream {
706    type Item = Result<SnapshotSinkV1Request, fidl::Error>;
707
708    fn poll_next(
709        mut self: std::pin::Pin<&mut Self>,
710        cx: &mut std::task::Context<'_>,
711    ) -> std::task::Poll<Option<Self::Item>> {
712        let this = &mut *self;
713        if this.inner.check_shutdown(cx) {
714            this.is_terminated = true;
715            return std::task::Poll::Ready(None);
716        }
717        if this.is_terminated {
718            panic!("polled SnapshotSinkV1RequestStream after completion");
719        }
720        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
721            |bytes, handles| {
722                match this.inner.channel().read_etc(cx, bytes, handles) {
723                    std::task::Poll::Ready(Ok(())) => {}
724                    std::task::Poll::Pending => return std::task::Poll::Pending,
725                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
726                        this.is_terminated = true;
727                        return std::task::Poll::Ready(None);
728                    }
729                    std::task::Poll::Ready(Err(e)) => {
730                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
731                            e.into(),
732                        ))))
733                    }
734                }
735
736                // A message has been received from the channel
737                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
738
739                std::task::Poll::Ready(Some(match header.ordinal {
740                    0x356eaec66aabbea5 => {
741                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
742                        let mut req = fidl::new_empty!(
743                            SnapshotSinkV1StoreNamedSnapshotRequest,
744                            fidl::encoding::DefaultFuchsiaResourceDialect
745                        );
746                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SnapshotSinkV1StoreNamedSnapshotRequest>(&header, _body_bytes, handles, &mut req)?;
747                        let control_handle =
748                            SnapshotSinkV1ControlHandle { inner: this.inner.clone() };
749                        Ok(SnapshotSinkV1Request::StoreNamedSnapshot {
750                            snapshot_name: req.snapshot_name,
751                            allocations_vmo_snapshot: req.allocations_vmo_snapshot,
752
753                            control_handle,
754                        })
755                    }
756                    _ => Err(fidl::Error::UnknownOrdinal {
757                        ordinal: header.ordinal,
758                        protocol_name:
759                            <SnapshotSinkV1Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
760                    }),
761                }))
762            },
763        )
764    }
765}
766
767/// Instrumented processes send application-initiated snapshots over this channel.
768///
769/// This channel is also used by the server to detect when an instrumented process exits.
770#[derive(Debug)]
771pub enum SnapshotSinkV1Request {
772    /// Asks the server to store a snapshot with the given name and the given allocations VMO.
773    ///
774    /// All the resources referenced by the given allocations VMO will be resolved using the
775    /// resources VMO that was shared by the process at registration time.
776    StoreNamedSnapshot {
777        snapshot_name: String,
778        allocations_vmo_snapshot: fidl::Vmo,
779        control_handle: SnapshotSinkV1ControlHandle,
780    },
781}
782
783impl SnapshotSinkV1Request {
784    #[allow(irrefutable_let_patterns)]
785    pub fn into_store_named_snapshot(
786        self,
787    ) -> Option<(String, fidl::Vmo, SnapshotSinkV1ControlHandle)> {
788        if let SnapshotSinkV1Request::StoreNamedSnapshot {
789            snapshot_name,
790            allocations_vmo_snapshot,
791            control_handle,
792        } = self
793        {
794            Some((snapshot_name, allocations_vmo_snapshot, control_handle))
795        } else {
796            None
797        }
798    }
799
800    /// Name of the method defined in FIDL
801    pub fn method_name(&self) -> &'static str {
802        match *self {
803            SnapshotSinkV1Request::StoreNamedSnapshot { .. } => "store_named_snapshot",
804        }
805    }
806}
807
808#[derive(Debug, Clone)]
809pub struct SnapshotSinkV1ControlHandle {
810    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
811}
812
813impl fidl::endpoints::ControlHandle for SnapshotSinkV1ControlHandle {
814    fn shutdown(&self) {
815        self.inner.shutdown()
816    }
817    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
818        self.inner.shutdown_with_epitaph(status)
819    }
820
821    fn is_closed(&self) -> bool {
822        self.inner.channel().is_closed()
823    }
824    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
825        self.inner.channel().on_closed()
826    }
827
828    #[cfg(target_os = "fuchsia")]
829    fn signal_peer(
830        &self,
831        clear_mask: zx::Signals,
832        set_mask: zx::Signals,
833    ) -> Result<(), zx_status::Status> {
834        use fidl::Peered;
835        self.inner.channel().signal_peer(clear_mask, set_mask)
836    }
837}
838
839impl SnapshotSinkV1ControlHandle {}
840
841mod internal {
842    use super::*;
843
844    impl fidl::encoding::ResourceTypeMarker for RegistryRegisterV1Request {
845        type Borrowed<'a> = &'a mut Self;
846        fn take_or_borrow<'a>(
847            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
848        ) -> Self::Borrowed<'a> {
849            value
850        }
851    }
852
853    unsafe impl fidl::encoding::TypeMarker for RegistryRegisterV1Request {
854        type Owned = Self;
855
856        #[inline(always)]
857        fn inline_align(_context: fidl::encoding::Context) -> usize {
858            4
859        }
860
861        #[inline(always)]
862        fn inline_size(_context: fidl::encoding::Context) -> usize {
863            16
864        }
865    }
866
867    unsafe impl
868        fidl::encoding::Encode<
869            RegistryRegisterV1Request,
870            fidl::encoding::DefaultFuchsiaResourceDialect,
871        > for &mut RegistryRegisterV1Request
872    {
873        #[inline]
874        unsafe fn encode(
875            self,
876            encoder: &mut fidl::encoding::Encoder<
877                '_,
878                fidl::encoding::DefaultFuchsiaResourceDialect,
879            >,
880            offset: usize,
881            _depth: fidl::encoding::Depth,
882        ) -> fidl::Result<()> {
883            encoder.debug_check_bounds::<RegistryRegisterV1Request>(offset);
884            // Delegate to tuple encoding.
885            fidl::encoding::Encode::<RegistryRegisterV1Request, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
886                (
887                    <fidl::encoding::HandleType<fidl::Process, { fidl::ObjectType::PROCESS.into_raw() }, 49231> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.process),
888                    <fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.allocations_vmo),
889                    <fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.resources_vmo),
890                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.snapshot_sink),
891                ),
892                encoder, offset, _depth
893            )
894        }
895    }
896    unsafe impl<
897            T0: fidl::encoding::Encode<
898                fidl::encoding::HandleType<
899                    fidl::Process,
900                    { fidl::ObjectType::PROCESS.into_raw() },
901                    49231,
902                >,
903                fidl::encoding::DefaultFuchsiaResourceDialect,
904            >,
905            T1: fidl::encoding::Encode<
906                fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>,
907                fidl::encoding::DefaultFuchsiaResourceDialect,
908            >,
909            T2: fidl::encoding::Encode<
910                fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>,
911                fidl::encoding::DefaultFuchsiaResourceDialect,
912            >,
913            T3: fidl::encoding::Encode<
914                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>>,
915                fidl::encoding::DefaultFuchsiaResourceDialect,
916            >,
917        >
918        fidl::encoding::Encode<
919            RegistryRegisterV1Request,
920            fidl::encoding::DefaultFuchsiaResourceDialect,
921        > for (T0, T1, T2, T3)
922    {
923        #[inline]
924        unsafe fn encode(
925            self,
926            encoder: &mut fidl::encoding::Encoder<
927                '_,
928                fidl::encoding::DefaultFuchsiaResourceDialect,
929            >,
930            offset: usize,
931            depth: fidl::encoding::Depth,
932        ) -> fidl::Result<()> {
933            encoder.debug_check_bounds::<RegistryRegisterV1Request>(offset);
934            // Zero out padding regions. There's no need to apply masks
935            // because the unmasked parts will be overwritten by fields.
936            // Write the fields.
937            self.0.encode(encoder, offset + 0, depth)?;
938            self.1.encode(encoder, offset + 4, depth)?;
939            self.2.encode(encoder, offset + 8, depth)?;
940            self.3.encode(encoder, offset + 12, depth)?;
941            Ok(())
942        }
943    }
944
945    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
946        for RegistryRegisterV1Request
947    {
948        #[inline(always)]
949        fn new_empty() -> Self {
950            Self {
951                process: fidl::new_empty!(fidl::encoding::HandleType<fidl::Process, { fidl::ObjectType::PROCESS.into_raw() }, 49231>, fidl::encoding::DefaultFuchsiaResourceDialect),
952                allocations_vmo: fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect),
953                resources_vmo: fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect),
954                snapshot_sink: fidl::new_empty!(
955                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>>,
956                    fidl::encoding::DefaultFuchsiaResourceDialect
957                ),
958            }
959        }
960
961        #[inline]
962        unsafe fn decode(
963            &mut self,
964            decoder: &mut fidl::encoding::Decoder<
965                '_,
966                fidl::encoding::DefaultFuchsiaResourceDialect,
967            >,
968            offset: usize,
969            _depth: fidl::encoding::Depth,
970        ) -> fidl::Result<()> {
971            decoder.debug_check_bounds::<Self>(offset);
972            // Verify that padding bytes are zero.
973            fidl::decode!(fidl::encoding::HandleType<fidl::Process, { fidl::ObjectType::PROCESS.into_raw() }, 49231>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.process, decoder, offset + 0, _depth)?;
974            fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.allocations_vmo, decoder, offset + 4, _depth)?;
975            fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.resources_vmo, decoder, offset + 8, _depth)?;
976            fidl::decode!(
977                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<SnapshotSinkV1Marker>>,
978                fidl::encoding::DefaultFuchsiaResourceDialect,
979                &mut self.snapshot_sink,
980                decoder,
981                offset + 12,
982                _depth
983            )?;
984            Ok(())
985        }
986    }
987
988    impl fidl::encoding::ResourceTypeMarker for SnapshotSinkV1StoreNamedSnapshotRequest {
989        type Borrowed<'a> = &'a mut Self;
990        fn take_or_borrow<'a>(
991            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
992        ) -> Self::Borrowed<'a> {
993            value
994        }
995    }
996
997    unsafe impl fidl::encoding::TypeMarker for SnapshotSinkV1StoreNamedSnapshotRequest {
998        type Owned = Self;
999
1000        #[inline(always)]
1001        fn inline_align(_context: fidl::encoding::Context) -> usize {
1002            8
1003        }
1004
1005        #[inline(always)]
1006        fn inline_size(_context: fidl::encoding::Context) -> usize {
1007            24
1008        }
1009    }
1010
1011    unsafe impl
1012        fidl::encoding::Encode<
1013            SnapshotSinkV1StoreNamedSnapshotRequest,
1014            fidl::encoding::DefaultFuchsiaResourceDialect,
1015        > for &mut SnapshotSinkV1StoreNamedSnapshotRequest
1016    {
1017        #[inline]
1018        unsafe fn encode(
1019            self,
1020            encoder: &mut fidl::encoding::Encoder<
1021                '_,
1022                fidl::encoding::DefaultFuchsiaResourceDialect,
1023            >,
1024            offset: usize,
1025            _depth: fidl::encoding::Depth,
1026        ) -> fidl::Result<()> {
1027            encoder.debug_check_bounds::<SnapshotSinkV1StoreNamedSnapshotRequest>(offset);
1028            // Delegate to tuple encoding.
1029            fidl::encoding::Encode::<
1030                SnapshotSinkV1StoreNamedSnapshotRequest,
1031                fidl::encoding::DefaultFuchsiaResourceDialect,
1032            >::encode(
1033                (
1034                    <fidl::encoding::BoundedString<32> as fidl::encoding::ValueTypeMarker>::borrow(
1035                        &self.snapshot_name,
1036                    ),
1037                    <fidl::encoding::HandleType<
1038                        fidl::Vmo,
1039                        { fidl::ObjectType::VMO.into_raw() },
1040                        49255,
1041                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1042                        &mut self.allocations_vmo_snapshot,
1043                    ),
1044                ),
1045                encoder,
1046                offset,
1047                _depth,
1048            )
1049        }
1050    }
1051    unsafe impl<
1052            T0: fidl::encoding::Encode<
1053                fidl::encoding::BoundedString<32>,
1054                fidl::encoding::DefaultFuchsiaResourceDialect,
1055            >,
1056            T1: fidl::encoding::Encode<
1057                fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>,
1058                fidl::encoding::DefaultFuchsiaResourceDialect,
1059            >,
1060        >
1061        fidl::encoding::Encode<
1062            SnapshotSinkV1StoreNamedSnapshotRequest,
1063            fidl::encoding::DefaultFuchsiaResourceDialect,
1064        > for (T0, T1)
1065    {
1066        #[inline]
1067        unsafe fn encode(
1068            self,
1069            encoder: &mut fidl::encoding::Encoder<
1070                '_,
1071                fidl::encoding::DefaultFuchsiaResourceDialect,
1072            >,
1073            offset: usize,
1074            depth: fidl::encoding::Depth,
1075        ) -> fidl::Result<()> {
1076            encoder.debug_check_bounds::<SnapshotSinkV1StoreNamedSnapshotRequest>(offset);
1077            // Zero out padding regions. There's no need to apply masks
1078            // because the unmasked parts will be overwritten by fields.
1079            unsafe {
1080                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1081                (ptr as *mut u64).write_unaligned(0);
1082            }
1083            // Write the fields.
1084            self.0.encode(encoder, offset + 0, depth)?;
1085            self.1.encode(encoder, offset + 16, depth)?;
1086            Ok(())
1087        }
1088    }
1089
1090    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1091        for SnapshotSinkV1StoreNamedSnapshotRequest
1092    {
1093        #[inline(always)]
1094        fn new_empty() -> Self {
1095            Self {
1096                snapshot_name: fidl::new_empty!(
1097                    fidl::encoding::BoundedString<32>,
1098                    fidl::encoding::DefaultFuchsiaResourceDialect
1099                ),
1100                allocations_vmo_snapshot: fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect),
1101            }
1102        }
1103
1104        #[inline]
1105        unsafe fn decode(
1106            &mut self,
1107            decoder: &mut fidl::encoding::Decoder<
1108                '_,
1109                fidl::encoding::DefaultFuchsiaResourceDialect,
1110            >,
1111            offset: usize,
1112            _depth: fidl::encoding::Depth,
1113        ) -> fidl::Result<()> {
1114            decoder.debug_check_bounds::<Self>(offset);
1115            // Verify that padding bytes are zero.
1116            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1117            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1118            let mask = 0xffffffff00000000u64;
1119            let maskedval = padval & mask;
1120            if maskedval != 0 {
1121                return Err(fidl::Error::NonZeroPadding {
1122                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1123                });
1124            }
1125            fidl::decode!(
1126                fidl::encoding::BoundedString<32>,
1127                fidl::encoding::DefaultFuchsiaResourceDialect,
1128                &mut self.snapshot_name,
1129                decoder,
1130                offset + 0,
1131                _depth
1132            )?;
1133            fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49255>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.allocations_vmo_snapshot, decoder, offset + 16, _depth)?;
1134            Ok(())
1135        }
1136    }
1137}