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