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