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