fidl_fuchsia_net_virtualization/
fidl_fuchsia_net_virtualization.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_virtualization__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct ControlCreateNetworkRequest {
16    pub config: Config,
17    pub network: fidl::endpoints::ServerEnd<NetworkMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for ControlCreateNetworkRequest
22{
23}
24
25#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26pub struct NetworkAddPortRequest {
27    pub port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
28    pub interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
29}
30
31impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for NetworkAddPortRequest {}
32
33#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
34pub struct ControlMarker;
35
36impl fidl::endpoints::ProtocolMarker for ControlMarker {
37    type Proxy = ControlProxy;
38    type RequestStream = ControlRequestStream;
39    #[cfg(target_os = "fuchsia")]
40    type SynchronousProxy = ControlSynchronousProxy;
41
42    const DEBUG_NAME: &'static str = "fuchsia.net.virtualization.Control";
43}
44impl fidl::endpoints::DiscoverableProtocolMarker for ControlMarker {}
45
46pub trait ControlProxyInterface: Send + Sync {
47    fn r#create_network(
48        &self,
49        config: &Config,
50        network: fidl::endpoints::ServerEnd<NetworkMarker>,
51    ) -> Result<(), fidl::Error>;
52}
53#[derive(Debug)]
54#[cfg(target_os = "fuchsia")]
55pub struct ControlSynchronousProxy {
56    client: fidl::client::sync::Client,
57}
58
59#[cfg(target_os = "fuchsia")]
60impl fidl::endpoints::SynchronousProxy for ControlSynchronousProxy {
61    type Proxy = ControlProxy;
62    type Protocol = ControlMarker;
63
64    fn from_channel(inner: fidl::Channel) -> Self {
65        Self::new(inner)
66    }
67
68    fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    fn as_channel(&self) -> &fidl::Channel {
73        self.client.as_channel()
74    }
75}
76
77#[cfg(target_os = "fuchsia")]
78impl ControlSynchronousProxy {
79    pub fn new(channel: fidl::Channel) -> Self {
80        let protocol_name = <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
81        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
82    }
83
84    pub fn into_channel(self) -> fidl::Channel {
85        self.client.into_channel()
86    }
87
88    /// Waits until an event arrives and returns it. It is safe for other
89    /// threads to make concurrent requests while waiting for an event.
90    pub fn wait_for_event(
91        &self,
92        deadline: zx::MonotonicInstant,
93    ) -> Result<ControlEvent, fidl::Error> {
94        ControlEvent::decode(self.client.wait_for_event(deadline)?)
95    }
96
97    /// Create a new network with configurable upstream connectivity.
98    ///
99    /// The network itself is always guaranteed to be created, but upstream
100    /// connectivity may not be established initially and may be lost at
101    /// any time.
102    ///
103    /// + request `config` network configuration.
104    /// + request `network` provides control over the created network. The
105    ///     protocol will be terminated after emitting a terminal event if the
106    ///     network cannot be added.
107    pub fn r#create_network(
108        &self,
109        mut config: &Config,
110        mut network: fidl::endpoints::ServerEnd<NetworkMarker>,
111    ) -> Result<(), fidl::Error> {
112        self.client.send::<ControlCreateNetworkRequest>(
113            (config, network),
114            0x4e5909b506960eaf,
115            fidl::encoding::DynamicFlags::empty(),
116        )
117    }
118}
119
120#[cfg(target_os = "fuchsia")]
121impl From<ControlSynchronousProxy> for zx::NullableHandle {
122    fn from(value: ControlSynchronousProxy) -> Self {
123        value.into_channel().into()
124    }
125}
126
127#[cfg(target_os = "fuchsia")]
128impl From<fidl::Channel> for ControlSynchronousProxy {
129    fn from(value: fidl::Channel) -> Self {
130        Self::new(value)
131    }
132}
133
134#[cfg(target_os = "fuchsia")]
135impl fidl::endpoints::FromClient for ControlSynchronousProxy {
136    type Protocol = ControlMarker;
137
138    fn from_client(value: fidl::endpoints::ClientEnd<ControlMarker>) -> Self {
139        Self::new(value.into_channel())
140    }
141}
142
143#[derive(Debug, Clone)]
144pub struct ControlProxy {
145    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
146}
147
148impl fidl::endpoints::Proxy for ControlProxy {
149    type Protocol = ControlMarker;
150
151    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
152        Self::new(inner)
153    }
154
155    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
156        self.client.into_channel().map_err(|client| Self { client })
157    }
158
159    fn as_channel(&self) -> &::fidl::AsyncChannel {
160        self.client.as_channel()
161    }
162}
163
164impl ControlProxy {
165    /// Create a new Proxy for fuchsia.net.virtualization/Control.
166    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
167        let protocol_name = <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
168        Self { client: fidl::client::Client::new(channel, protocol_name) }
169    }
170
171    /// Get a Stream of events from the remote end of the protocol.
172    ///
173    /// # Panics
174    ///
175    /// Panics if the event stream was already taken.
176    pub fn take_event_stream(&self) -> ControlEventStream {
177        ControlEventStream { event_receiver: self.client.take_event_receiver() }
178    }
179
180    /// Create a new network with configurable upstream connectivity.
181    ///
182    /// The network itself is always guaranteed to be created, but upstream
183    /// connectivity may not be established initially and may be lost at
184    /// any time.
185    ///
186    /// + request `config` network configuration.
187    /// + request `network` provides control over the created network. The
188    ///     protocol will be terminated after emitting a terminal event if the
189    ///     network cannot be added.
190    pub fn r#create_network(
191        &self,
192        mut config: &Config,
193        mut network: fidl::endpoints::ServerEnd<NetworkMarker>,
194    ) -> Result<(), fidl::Error> {
195        ControlProxyInterface::r#create_network(self, config, network)
196    }
197}
198
199impl ControlProxyInterface for ControlProxy {
200    fn r#create_network(
201        &self,
202        mut config: &Config,
203        mut network: fidl::endpoints::ServerEnd<NetworkMarker>,
204    ) -> Result<(), fidl::Error> {
205        self.client.send::<ControlCreateNetworkRequest>(
206            (config, network),
207            0x4e5909b506960eaf,
208            fidl::encoding::DynamicFlags::empty(),
209        )
210    }
211}
212
213pub struct ControlEventStream {
214    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
215}
216
217impl std::marker::Unpin for ControlEventStream {}
218
219impl futures::stream::FusedStream for ControlEventStream {
220    fn is_terminated(&self) -> bool {
221        self.event_receiver.is_terminated()
222    }
223}
224
225impl futures::Stream for ControlEventStream {
226    type Item = Result<ControlEvent, fidl::Error>;
227
228    fn poll_next(
229        mut self: std::pin::Pin<&mut Self>,
230        cx: &mut std::task::Context<'_>,
231    ) -> std::task::Poll<Option<Self::Item>> {
232        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
233            &mut self.event_receiver,
234            cx
235        )?) {
236            Some(buf) => std::task::Poll::Ready(Some(ControlEvent::decode(buf))),
237            None => std::task::Poll::Ready(None),
238        }
239    }
240}
241
242#[derive(Debug)]
243pub enum ControlEvent {}
244
245impl ControlEvent {
246    /// Decodes a message buffer as a [`ControlEvent`].
247    fn decode(
248        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
249    ) -> Result<ControlEvent, fidl::Error> {
250        let (bytes, _handles) = buf.split_mut();
251        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
252        debug_assert_eq!(tx_header.tx_id, 0);
253        match tx_header.ordinal {
254            _ => Err(fidl::Error::UnknownOrdinal {
255                ordinal: tx_header.ordinal,
256                protocol_name: <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
257            }),
258        }
259    }
260}
261
262/// A Stream of incoming requests for fuchsia.net.virtualization/Control.
263pub struct ControlRequestStream {
264    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
265    is_terminated: bool,
266}
267
268impl std::marker::Unpin for ControlRequestStream {}
269
270impl futures::stream::FusedStream for ControlRequestStream {
271    fn is_terminated(&self) -> bool {
272        self.is_terminated
273    }
274}
275
276impl fidl::endpoints::RequestStream for ControlRequestStream {
277    type Protocol = ControlMarker;
278    type ControlHandle = ControlControlHandle;
279
280    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
281        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
282    }
283
284    fn control_handle(&self) -> Self::ControlHandle {
285        ControlControlHandle { inner: self.inner.clone() }
286    }
287
288    fn into_inner(
289        self,
290    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
291    {
292        (self.inner, self.is_terminated)
293    }
294
295    fn from_inner(
296        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
297        is_terminated: bool,
298    ) -> Self {
299        Self { inner, is_terminated }
300    }
301}
302
303impl futures::Stream for ControlRequestStream {
304    type Item = Result<ControlRequest, fidl::Error>;
305
306    fn poll_next(
307        mut self: std::pin::Pin<&mut Self>,
308        cx: &mut std::task::Context<'_>,
309    ) -> std::task::Poll<Option<Self::Item>> {
310        let this = &mut *self;
311        if this.inner.check_shutdown(cx) {
312            this.is_terminated = true;
313            return std::task::Poll::Ready(None);
314        }
315        if this.is_terminated {
316            panic!("polled ControlRequestStream after completion");
317        }
318        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
319            |bytes, handles| {
320                match this.inner.channel().read_etc(cx, bytes, handles) {
321                    std::task::Poll::Ready(Ok(())) => {}
322                    std::task::Poll::Pending => return std::task::Poll::Pending,
323                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
324                        this.is_terminated = true;
325                        return std::task::Poll::Ready(None);
326                    }
327                    std::task::Poll::Ready(Err(e)) => {
328                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
329                            e.into(),
330                        ))));
331                    }
332                }
333
334                // A message has been received from the channel
335                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
336
337                std::task::Poll::Ready(Some(match header.ordinal {
338                    0x4e5909b506960eaf => {
339                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
340                        let mut req = fidl::new_empty!(
341                            ControlCreateNetworkRequest,
342                            fidl::encoding::DefaultFuchsiaResourceDialect
343                        );
344                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControlCreateNetworkRequest>(&header, _body_bytes, handles, &mut req)?;
345                        let control_handle = ControlControlHandle { inner: this.inner.clone() };
346                        Ok(ControlRequest::CreateNetwork {
347                            config: req.config,
348                            network: req.network,
349
350                            control_handle,
351                        })
352                    }
353                    _ => Err(fidl::Error::UnknownOrdinal {
354                        ordinal: header.ordinal,
355                        protocol_name:
356                            <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
357                    }),
358                }))
359            },
360        )
361    }
362}
363
364/// Provides control over virtualization network configuration.
365#[derive(Debug)]
366pub enum ControlRequest {
367    /// Create a new network with configurable upstream connectivity.
368    ///
369    /// The network itself is always guaranteed to be created, but upstream
370    /// connectivity may not be established initially and may be lost at
371    /// any time.
372    ///
373    /// + request `config` network configuration.
374    /// + request `network` provides control over the created network. The
375    ///     protocol will be terminated after emitting a terminal event if the
376    ///     network cannot be added.
377    CreateNetwork {
378        config: Config,
379        network: fidl::endpoints::ServerEnd<NetworkMarker>,
380        control_handle: ControlControlHandle,
381    },
382}
383
384impl ControlRequest {
385    #[allow(irrefutable_let_patterns)]
386    pub fn into_create_network(
387        self,
388    ) -> Option<(Config, fidl::endpoints::ServerEnd<NetworkMarker>, ControlControlHandle)> {
389        if let ControlRequest::CreateNetwork { config, network, control_handle } = self {
390            Some((config, network, control_handle))
391        } else {
392            None
393        }
394    }
395
396    /// Name of the method defined in FIDL
397    pub fn method_name(&self) -> &'static str {
398        match *self {
399            ControlRequest::CreateNetwork { .. } => "create_network",
400        }
401    }
402}
403
404#[derive(Debug, Clone)]
405pub struct ControlControlHandle {
406    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
407}
408
409impl fidl::endpoints::ControlHandle for ControlControlHandle {
410    fn shutdown(&self) {
411        self.inner.shutdown()
412    }
413
414    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
415        self.inner.shutdown_with_epitaph(status)
416    }
417
418    fn is_closed(&self) -> bool {
419        self.inner.channel().is_closed()
420    }
421    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
422        self.inner.channel().on_closed()
423    }
424
425    #[cfg(target_os = "fuchsia")]
426    fn signal_peer(
427        &self,
428        clear_mask: zx::Signals,
429        set_mask: zx::Signals,
430    ) -> Result<(), zx_status::Status> {
431        use fidl::Peered;
432        self.inner.channel().signal_peer(clear_mask, set_mask)
433    }
434}
435
436impl ControlControlHandle {}
437
438#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
439pub struct InterfaceMarker;
440
441impl fidl::endpoints::ProtocolMarker for InterfaceMarker {
442    type Proxy = InterfaceProxy;
443    type RequestStream = InterfaceRequestStream;
444    #[cfg(target_os = "fuchsia")]
445    type SynchronousProxy = InterfaceSynchronousProxy;
446
447    const DEBUG_NAME: &'static str = "(anonymous) Interface";
448}
449
450pub trait InterfaceProxyInterface: Send + Sync {}
451#[derive(Debug)]
452#[cfg(target_os = "fuchsia")]
453pub struct InterfaceSynchronousProxy {
454    client: fidl::client::sync::Client,
455}
456
457#[cfg(target_os = "fuchsia")]
458impl fidl::endpoints::SynchronousProxy for InterfaceSynchronousProxy {
459    type Proxy = InterfaceProxy;
460    type Protocol = InterfaceMarker;
461
462    fn from_channel(inner: fidl::Channel) -> Self {
463        Self::new(inner)
464    }
465
466    fn into_channel(self) -> fidl::Channel {
467        self.client.into_channel()
468    }
469
470    fn as_channel(&self) -> &fidl::Channel {
471        self.client.as_channel()
472    }
473}
474
475#[cfg(target_os = "fuchsia")]
476impl InterfaceSynchronousProxy {
477    pub fn new(channel: fidl::Channel) -> Self {
478        let protocol_name = <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
479        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
480    }
481
482    pub fn into_channel(self) -> fidl::Channel {
483        self.client.into_channel()
484    }
485
486    /// Waits until an event arrives and returns it. It is safe for other
487    /// threads to make concurrent requests while waiting for an event.
488    pub fn wait_for_event(
489        &self,
490        deadline: zx::MonotonicInstant,
491    ) -> Result<InterfaceEvent, fidl::Error> {
492        InterfaceEvent::decode(self.client.wait_for_event(deadline)?)
493    }
494}
495
496#[cfg(target_os = "fuchsia")]
497impl From<InterfaceSynchronousProxy> for zx::NullableHandle {
498    fn from(value: InterfaceSynchronousProxy) -> Self {
499        value.into_channel().into()
500    }
501}
502
503#[cfg(target_os = "fuchsia")]
504impl From<fidl::Channel> for InterfaceSynchronousProxy {
505    fn from(value: fidl::Channel) -> Self {
506        Self::new(value)
507    }
508}
509
510#[cfg(target_os = "fuchsia")]
511impl fidl::endpoints::FromClient for InterfaceSynchronousProxy {
512    type Protocol = InterfaceMarker;
513
514    fn from_client(value: fidl::endpoints::ClientEnd<InterfaceMarker>) -> Self {
515        Self::new(value.into_channel())
516    }
517}
518
519#[derive(Debug, Clone)]
520pub struct InterfaceProxy {
521    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
522}
523
524impl fidl::endpoints::Proxy for InterfaceProxy {
525    type Protocol = InterfaceMarker;
526
527    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
528        Self::new(inner)
529    }
530
531    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
532        self.client.into_channel().map_err(|client| Self { client })
533    }
534
535    fn as_channel(&self) -> &::fidl::AsyncChannel {
536        self.client.as_channel()
537    }
538}
539
540impl InterfaceProxy {
541    /// Create a new Proxy for fuchsia.net.virtualization/Interface.
542    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
543        let protocol_name = <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
544        Self { client: fidl::client::Client::new(channel, protocol_name) }
545    }
546
547    /// Get a Stream of events from the remote end of the protocol.
548    ///
549    /// # Panics
550    ///
551    /// Panics if the event stream was already taken.
552    pub fn take_event_stream(&self) -> InterfaceEventStream {
553        InterfaceEventStream { event_receiver: self.client.take_event_receiver() }
554    }
555}
556
557impl InterfaceProxyInterface for InterfaceProxy {}
558
559pub struct InterfaceEventStream {
560    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
561}
562
563impl std::marker::Unpin for InterfaceEventStream {}
564
565impl futures::stream::FusedStream for InterfaceEventStream {
566    fn is_terminated(&self) -> bool {
567        self.event_receiver.is_terminated()
568    }
569}
570
571impl futures::Stream for InterfaceEventStream {
572    type Item = Result<InterfaceEvent, fidl::Error>;
573
574    fn poll_next(
575        mut self: std::pin::Pin<&mut Self>,
576        cx: &mut std::task::Context<'_>,
577    ) -> std::task::Poll<Option<Self::Item>> {
578        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
579            &mut self.event_receiver,
580            cx
581        )?) {
582            Some(buf) => std::task::Poll::Ready(Some(InterfaceEvent::decode(buf))),
583            None => std::task::Poll::Ready(None),
584        }
585    }
586}
587
588#[derive(Debug)]
589pub enum InterfaceEvent {
590    OnRemoved { reason: InterfaceRemovalReason },
591}
592
593impl InterfaceEvent {
594    #[allow(irrefutable_let_patterns)]
595    pub fn into_on_removed(self) -> Option<InterfaceRemovalReason> {
596        if let InterfaceEvent::OnRemoved { reason } = self { Some((reason)) } else { None }
597    }
598
599    /// Decodes a message buffer as a [`InterfaceEvent`].
600    fn decode(
601        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
602    ) -> Result<InterfaceEvent, fidl::Error> {
603        let (bytes, _handles) = buf.split_mut();
604        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
605        debug_assert_eq!(tx_header.tx_id, 0);
606        match tx_header.ordinal {
607            0x4785571ae39a2617 => {
608                let mut out = fidl::new_empty!(
609                    InterfaceOnRemovedRequest,
610                    fidl::encoding::DefaultFuchsiaResourceDialect
611                );
612                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InterfaceOnRemovedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
613                Ok((InterfaceEvent::OnRemoved { reason: out.reason }))
614            }
615            _ => Err(fidl::Error::UnknownOrdinal {
616                ordinal: tx_header.ordinal,
617                protocol_name: <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
618            }),
619        }
620    }
621}
622
623/// A Stream of incoming requests for fuchsia.net.virtualization/Interface.
624pub struct InterfaceRequestStream {
625    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
626    is_terminated: bool,
627}
628
629impl std::marker::Unpin for InterfaceRequestStream {}
630
631impl futures::stream::FusedStream for InterfaceRequestStream {
632    fn is_terminated(&self) -> bool {
633        self.is_terminated
634    }
635}
636
637impl fidl::endpoints::RequestStream for InterfaceRequestStream {
638    type Protocol = InterfaceMarker;
639    type ControlHandle = InterfaceControlHandle;
640
641    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
642        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
643    }
644
645    fn control_handle(&self) -> Self::ControlHandle {
646        InterfaceControlHandle { inner: self.inner.clone() }
647    }
648
649    fn into_inner(
650        self,
651    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
652    {
653        (self.inner, self.is_terminated)
654    }
655
656    fn from_inner(
657        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
658        is_terminated: bool,
659    ) -> Self {
660        Self { inner, is_terminated }
661    }
662}
663
664impl futures::Stream for InterfaceRequestStream {
665    type Item = Result<InterfaceRequest, fidl::Error>;
666
667    fn poll_next(
668        mut self: std::pin::Pin<&mut Self>,
669        cx: &mut std::task::Context<'_>,
670    ) -> std::task::Poll<Option<Self::Item>> {
671        let this = &mut *self;
672        if this.inner.check_shutdown(cx) {
673            this.is_terminated = true;
674            return std::task::Poll::Ready(None);
675        }
676        if this.is_terminated {
677            panic!("polled InterfaceRequestStream after completion");
678        }
679        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
680            |bytes, handles| {
681                match this.inner.channel().read_etc(cx, bytes, handles) {
682                    std::task::Poll::Ready(Ok(())) => {}
683                    std::task::Poll::Pending => return std::task::Poll::Pending,
684                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
685                        this.is_terminated = true;
686                        return std::task::Poll::Ready(None);
687                    }
688                    std::task::Poll::Ready(Err(e)) => {
689                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
690                            e.into(),
691                        ))));
692                    }
693                }
694
695                // A message has been received from the channel
696                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
697
698                std::task::Poll::Ready(Some(match header.ordinal {
699                    _ => Err(fidl::Error::UnknownOrdinal {
700                        ordinal: header.ordinal,
701                        protocol_name:
702                            <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
703                    }),
704                }))
705            },
706        )
707    }
708}
709
710/// Provides control over an interface.
711///
712/// This protocol encodes the lifetime of the underlying interface in both
713/// directions, that is:
714/// - if the client end is closed, the server will detach the interface
715///     from the network it belongs to and detach the network device;
716/// - if the server end is closed, the interface has been detached from
717///     the network it was attached to and destroyed.
718#[derive(Debug)]
719pub enum InterfaceRequest {}
720
721impl InterfaceRequest {
722    /// Name of the method defined in FIDL
723    pub fn method_name(&self) -> &'static str {
724        match *self {}
725    }
726}
727
728#[derive(Debug, Clone)]
729pub struct InterfaceControlHandle {
730    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
731}
732
733impl fidl::endpoints::ControlHandle for InterfaceControlHandle {
734    fn shutdown(&self) {
735        self.inner.shutdown()
736    }
737
738    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
739        self.inner.shutdown_with_epitaph(status)
740    }
741
742    fn is_closed(&self) -> bool {
743        self.inner.channel().is_closed()
744    }
745    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
746        self.inner.channel().on_closed()
747    }
748
749    #[cfg(target_os = "fuchsia")]
750    fn signal_peer(
751        &self,
752        clear_mask: zx::Signals,
753        set_mask: zx::Signals,
754    ) -> Result<(), zx_status::Status> {
755        use fidl::Peered;
756        self.inner.channel().signal_peer(clear_mask, set_mask)
757    }
758}
759
760impl InterfaceControlHandle {
761    pub fn send_on_removed(&self, mut reason: InterfaceRemovalReason) -> Result<(), fidl::Error> {
762        self.inner.send::<InterfaceOnRemovedRequest>(
763            (reason,),
764            0,
765            0x4785571ae39a2617,
766            fidl::encoding::DynamicFlags::empty(),
767        )
768    }
769}
770
771#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
772pub struct NetworkMarker;
773
774impl fidl::endpoints::ProtocolMarker for NetworkMarker {
775    type Proxy = NetworkProxy;
776    type RequestStream = NetworkRequestStream;
777    #[cfg(target_os = "fuchsia")]
778    type SynchronousProxy = NetworkSynchronousProxy;
779
780    const DEBUG_NAME: &'static str = "(anonymous) Network";
781}
782
783pub trait NetworkProxyInterface: Send + Sync {
784    fn r#add_port(
785        &self,
786        port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
787        interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
788    ) -> Result<(), fidl::Error>;
789}
790#[derive(Debug)]
791#[cfg(target_os = "fuchsia")]
792pub struct NetworkSynchronousProxy {
793    client: fidl::client::sync::Client,
794}
795
796#[cfg(target_os = "fuchsia")]
797impl fidl::endpoints::SynchronousProxy for NetworkSynchronousProxy {
798    type Proxy = NetworkProxy;
799    type Protocol = NetworkMarker;
800
801    fn from_channel(inner: fidl::Channel) -> Self {
802        Self::new(inner)
803    }
804
805    fn into_channel(self) -> fidl::Channel {
806        self.client.into_channel()
807    }
808
809    fn as_channel(&self) -> &fidl::Channel {
810        self.client.as_channel()
811    }
812}
813
814#[cfg(target_os = "fuchsia")]
815impl NetworkSynchronousProxy {
816    pub fn new(channel: fidl::Channel) -> Self {
817        let protocol_name = <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
818        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
819    }
820
821    pub fn into_channel(self) -> fidl::Channel {
822        self.client.into_channel()
823    }
824
825    /// Waits until an event arrives and returns it. It is safe for other
826    /// threads to make concurrent requests while waiting for an event.
827    pub fn wait_for_event(
828        &self,
829        deadline: zx::MonotonicInstant,
830    ) -> Result<NetworkEvent, fidl::Error> {
831        NetworkEvent::decode(self.client.wait_for_event(deadline)?)
832    }
833
834    /// Adds a port to the network.
835    ///
836    /// + request `port` port to be added.
837    /// + request `interface` provides control over the interface.
838    pub fn r#add_port(
839        &self,
840        mut port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
841        mut interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
842    ) -> Result<(), fidl::Error> {
843        self.client.send::<NetworkAddPortRequest>(
844            (port, interface),
845            0x7ad6a60c931a3f4e,
846            fidl::encoding::DynamicFlags::empty(),
847        )
848    }
849}
850
851#[cfg(target_os = "fuchsia")]
852impl From<NetworkSynchronousProxy> for zx::NullableHandle {
853    fn from(value: NetworkSynchronousProxy) -> Self {
854        value.into_channel().into()
855    }
856}
857
858#[cfg(target_os = "fuchsia")]
859impl From<fidl::Channel> for NetworkSynchronousProxy {
860    fn from(value: fidl::Channel) -> Self {
861        Self::new(value)
862    }
863}
864
865#[cfg(target_os = "fuchsia")]
866impl fidl::endpoints::FromClient for NetworkSynchronousProxy {
867    type Protocol = NetworkMarker;
868
869    fn from_client(value: fidl::endpoints::ClientEnd<NetworkMarker>) -> Self {
870        Self::new(value.into_channel())
871    }
872}
873
874#[derive(Debug, Clone)]
875pub struct NetworkProxy {
876    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
877}
878
879impl fidl::endpoints::Proxy for NetworkProxy {
880    type Protocol = NetworkMarker;
881
882    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
883        Self::new(inner)
884    }
885
886    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
887        self.client.into_channel().map_err(|client| Self { client })
888    }
889
890    fn as_channel(&self) -> &::fidl::AsyncChannel {
891        self.client.as_channel()
892    }
893}
894
895impl NetworkProxy {
896    /// Create a new Proxy for fuchsia.net.virtualization/Network.
897    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
898        let protocol_name = <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
899        Self { client: fidl::client::Client::new(channel, protocol_name) }
900    }
901
902    /// Get a Stream of events from the remote end of the protocol.
903    ///
904    /// # Panics
905    ///
906    /// Panics if the event stream was already taken.
907    pub fn take_event_stream(&self) -> NetworkEventStream {
908        NetworkEventStream { event_receiver: self.client.take_event_receiver() }
909    }
910
911    /// Adds a port to the network.
912    ///
913    /// + request `port` port to be added.
914    /// + request `interface` provides control over the interface.
915    pub fn r#add_port(
916        &self,
917        mut port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
918        mut interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
919    ) -> Result<(), fidl::Error> {
920        NetworkProxyInterface::r#add_port(self, port, interface)
921    }
922}
923
924impl NetworkProxyInterface for NetworkProxy {
925    fn r#add_port(
926        &self,
927        mut port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
928        mut interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
929    ) -> Result<(), fidl::Error> {
930        self.client.send::<NetworkAddPortRequest>(
931            (port, interface),
932            0x7ad6a60c931a3f4e,
933            fidl::encoding::DynamicFlags::empty(),
934        )
935    }
936}
937
938pub struct NetworkEventStream {
939    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
940}
941
942impl std::marker::Unpin for NetworkEventStream {}
943
944impl futures::stream::FusedStream for NetworkEventStream {
945    fn is_terminated(&self) -> bool {
946        self.event_receiver.is_terminated()
947    }
948}
949
950impl futures::Stream for NetworkEventStream {
951    type Item = Result<NetworkEvent, 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        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
958            &mut self.event_receiver,
959            cx
960        )?) {
961            Some(buf) => std::task::Poll::Ready(Some(NetworkEvent::decode(buf))),
962            None => std::task::Poll::Ready(None),
963        }
964    }
965}
966
967#[derive(Debug)]
968pub enum NetworkEvent {
969    OnRemoved { reason: NetworkRemovalReason },
970}
971
972impl NetworkEvent {
973    #[allow(irrefutable_let_patterns)]
974    pub fn into_on_removed(self) -> Option<NetworkRemovalReason> {
975        if let NetworkEvent::OnRemoved { reason } = self { Some((reason)) } else { None }
976    }
977
978    /// Decodes a message buffer as a [`NetworkEvent`].
979    fn decode(
980        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
981    ) -> Result<NetworkEvent, fidl::Error> {
982        let (bytes, _handles) = buf.split_mut();
983        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
984        debug_assert_eq!(tx_header.tx_id, 0);
985        match tx_header.ordinal {
986            0xfe80656d1e5ec4a => {
987                let mut out = fidl::new_empty!(
988                    NetworkOnRemovedRequest,
989                    fidl::encoding::DefaultFuchsiaResourceDialect
990                );
991                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<NetworkOnRemovedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
992                Ok((NetworkEvent::OnRemoved { reason: out.reason }))
993            }
994            _ => Err(fidl::Error::UnknownOrdinal {
995                ordinal: tx_header.ordinal,
996                protocol_name: <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
997            }),
998        }
999    }
1000}
1001
1002/// A Stream of incoming requests for fuchsia.net.virtualization/Network.
1003pub struct NetworkRequestStream {
1004    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1005    is_terminated: bool,
1006}
1007
1008impl std::marker::Unpin for NetworkRequestStream {}
1009
1010impl futures::stream::FusedStream for NetworkRequestStream {
1011    fn is_terminated(&self) -> bool {
1012        self.is_terminated
1013    }
1014}
1015
1016impl fidl::endpoints::RequestStream for NetworkRequestStream {
1017    type Protocol = NetworkMarker;
1018    type ControlHandle = NetworkControlHandle;
1019
1020    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1021        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1022    }
1023
1024    fn control_handle(&self) -> Self::ControlHandle {
1025        NetworkControlHandle { inner: self.inner.clone() }
1026    }
1027
1028    fn into_inner(
1029        self,
1030    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1031    {
1032        (self.inner, self.is_terminated)
1033    }
1034
1035    fn from_inner(
1036        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1037        is_terminated: bool,
1038    ) -> Self {
1039        Self { inner, is_terminated }
1040    }
1041}
1042
1043impl futures::Stream for NetworkRequestStream {
1044    type Item = Result<NetworkRequest, fidl::Error>;
1045
1046    fn poll_next(
1047        mut self: std::pin::Pin<&mut Self>,
1048        cx: &mut std::task::Context<'_>,
1049    ) -> std::task::Poll<Option<Self::Item>> {
1050        let this = &mut *self;
1051        if this.inner.check_shutdown(cx) {
1052            this.is_terminated = true;
1053            return std::task::Poll::Ready(None);
1054        }
1055        if this.is_terminated {
1056            panic!("polled NetworkRequestStream after completion");
1057        }
1058        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1059            |bytes, handles| {
1060                match this.inner.channel().read_etc(cx, bytes, handles) {
1061                    std::task::Poll::Ready(Ok(())) => {}
1062                    std::task::Poll::Pending => return std::task::Poll::Pending,
1063                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1064                        this.is_terminated = true;
1065                        return std::task::Poll::Ready(None);
1066                    }
1067                    std::task::Poll::Ready(Err(e)) => {
1068                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1069                            e.into(),
1070                        ))));
1071                    }
1072                }
1073
1074                // A message has been received from the channel
1075                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1076
1077                std::task::Poll::Ready(Some(match header.ordinal {
1078                    0x7ad6a60c931a3f4e => {
1079                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1080                        let mut req = fidl::new_empty!(
1081                            NetworkAddPortRequest,
1082                            fidl::encoding::DefaultFuchsiaResourceDialect
1083                        );
1084                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<NetworkAddPortRequest>(&header, _body_bytes, handles, &mut req)?;
1085                        let control_handle = NetworkControlHandle { inner: this.inner.clone() };
1086                        Ok(NetworkRequest::AddPort {
1087                            port: req.port,
1088                            interface: req.interface,
1089
1090                            control_handle,
1091                        })
1092                    }
1093                    _ => Err(fidl::Error::UnknownOrdinal {
1094                        ordinal: header.ordinal,
1095                        protocol_name:
1096                            <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1097                    }),
1098                }))
1099            },
1100        )
1101    }
1102}
1103
1104/// Provides control over a network.
1105///
1106/// This protocol encodes the lifetime of the underlying network in both
1107/// directions, that is:
1108/// - if the client end is closed: all interfaces added to the network
1109///     (not including any used to provide upstream connectivity) will be
1110///     removed and destroyed, and the network will be removed;
1111/// - if the server end is closed, all interfaces on the network and the
1112///     network itself have been destroyed.
1113#[derive(Debug)]
1114pub enum NetworkRequest {
1115    /// Adds a port to the network.
1116    ///
1117    /// + request `port` port to be added.
1118    /// + request `interface` provides control over the interface.
1119    AddPort {
1120        port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1121        interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
1122        control_handle: NetworkControlHandle,
1123    },
1124}
1125
1126impl NetworkRequest {
1127    #[allow(irrefutable_let_patterns)]
1128    pub fn into_add_port(
1129        self,
1130    ) -> Option<(
1131        fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1132        fidl::endpoints::ServerEnd<InterfaceMarker>,
1133        NetworkControlHandle,
1134    )> {
1135        if let NetworkRequest::AddPort { port, interface, control_handle } = self {
1136            Some((port, interface, control_handle))
1137        } else {
1138            None
1139        }
1140    }
1141
1142    /// Name of the method defined in FIDL
1143    pub fn method_name(&self) -> &'static str {
1144        match *self {
1145            NetworkRequest::AddPort { .. } => "add_port",
1146        }
1147    }
1148}
1149
1150#[derive(Debug, Clone)]
1151pub struct NetworkControlHandle {
1152    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1153}
1154
1155impl fidl::endpoints::ControlHandle for NetworkControlHandle {
1156    fn shutdown(&self) {
1157        self.inner.shutdown()
1158    }
1159
1160    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1161        self.inner.shutdown_with_epitaph(status)
1162    }
1163
1164    fn is_closed(&self) -> bool {
1165        self.inner.channel().is_closed()
1166    }
1167    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1168        self.inner.channel().on_closed()
1169    }
1170
1171    #[cfg(target_os = "fuchsia")]
1172    fn signal_peer(
1173        &self,
1174        clear_mask: zx::Signals,
1175        set_mask: zx::Signals,
1176    ) -> Result<(), zx_status::Status> {
1177        use fidl::Peered;
1178        self.inner.channel().signal_peer(clear_mask, set_mask)
1179    }
1180}
1181
1182impl NetworkControlHandle {
1183    pub fn send_on_removed(&self, mut reason: NetworkRemovalReason) -> Result<(), fidl::Error> {
1184        self.inner.send::<NetworkOnRemovedRequest>(
1185            (reason,),
1186            0,
1187            0xfe80656d1e5ec4a,
1188            fidl::encoding::DynamicFlags::empty(),
1189        )
1190    }
1191}
1192
1193mod internal {
1194    use super::*;
1195
1196    impl fidl::encoding::ResourceTypeMarker for ControlCreateNetworkRequest {
1197        type Borrowed<'a> = &'a mut Self;
1198        fn take_or_borrow<'a>(
1199            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1200        ) -> Self::Borrowed<'a> {
1201            value
1202        }
1203    }
1204
1205    unsafe impl fidl::encoding::TypeMarker for ControlCreateNetworkRequest {
1206        type Owned = Self;
1207
1208        #[inline(always)]
1209        fn inline_align(_context: fidl::encoding::Context) -> usize {
1210            8
1211        }
1212
1213        #[inline(always)]
1214        fn inline_size(_context: fidl::encoding::Context) -> usize {
1215            24
1216        }
1217    }
1218
1219    unsafe impl
1220        fidl::encoding::Encode<
1221            ControlCreateNetworkRequest,
1222            fidl::encoding::DefaultFuchsiaResourceDialect,
1223        > for &mut ControlCreateNetworkRequest
1224    {
1225        #[inline]
1226        unsafe fn encode(
1227            self,
1228            encoder: &mut fidl::encoding::Encoder<
1229                '_,
1230                fidl::encoding::DefaultFuchsiaResourceDialect,
1231            >,
1232            offset: usize,
1233            _depth: fidl::encoding::Depth,
1234        ) -> fidl::Result<()> {
1235            encoder.debug_check_bounds::<ControlCreateNetworkRequest>(offset);
1236            // Delegate to tuple encoding.
1237            fidl::encoding::Encode::<ControlCreateNetworkRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1238                (
1239                    <Config as fidl::encoding::ValueTypeMarker>::borrow(&self.config),
1240                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.network),
1241                ),
1242                encoder, offset, _depth
1243            )
1244        }
1245    }
1246    unsafe impl<
1247        T0: fidl::encoding::Encode<Config, fidl::encoding::DefaultFuchsiaResourceDialect>,
1248        T1: fidl::encoding::Encode<
1249                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>>,
1250                fidl::encoding::DefaultFuchsiaResourceDialect,
1251            >,
1252    >
1253        fidl::encoding::Encode<
1254            ControlCreateNetworkRequest,
1255            fidl::encoding::DefaultFuchsiaResourceDialect,
1256        > for (T0, T1)
1257    {
1258        #[inline]
1259        unsafe fn encode(
1260            self,
1261            encoder: &mut fidl::encoding::Encoder<
1262                '_,
1263                fidl::encoding::DefaultFuchsiaResourceDialect,
1264            >,
1265            offset: usize,
1266            depth: fidl::encoding::Depth,
1267        ) -> fidl::Result<()> {
1268            encoder.debug_check_bounds::<ControlCreateNetworkRequest>(offset);
1269            // Zero out padding regions. There's no need to apply masks
1270            // because the unmasked parts will be overwritten by fields.
1271            unsafe {
1272                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1273                (ptr as *mut u64).write_unaligned(0);
1274            }
1275            // Write the fields.
1276            self.0.encode(encoder, offset + 0, depth)?;
1277            self.1.encode(encoder, offset + 16, depth)?;
1278            Ok(())
1279        }
1280    }
1281
1282    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1283        for ControlCreateNetworkRequest
1284    {
1285        #[inline(always)]
1286        fn new_empty() -> Self {
1287            Self {
1288                config: fidl::new_empty!(Config, fidl::encoding::DefaultFuchsiaResourceDialect),
1289                network: fidl::new_empty!(
1290                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>>,
1291                    fidl::encoding::DefaultFuchsiaResourceDialect
1292                ),
1293            }
1294        }
1295
1296        #[inline]
1297        unsafe fn decode(
1298            &mut self,
1299            decoder: &mut fidl::encoding::Decoder<
1300                '_,
1301                fidl::encoding::DefaultFuchsiaResourceDialect,
1302            >,
1303            offset: usize,
1304            _depth: fidl::encoding::Depth,
1305        ) -> fidl::Result<()> {
1306            decoder.debug_check_bounds::<Self>(offset);
1307            // Verify that padding bytes are zero.
1308            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1309            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1310            let mask = 0xffffffff00000000u64;
1311            let maskedval = padval & mask;
1312            if maskedval != 0 {
1313                return Err(fidl::Error::NonZeroPadding {
1314                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1315                });
1316            }
1317            fidl::decode!(
1318                Config,
1319                fidl::encoding::DefaultFuchsiaResourceDialect,
1320                &mut self.config,
1321                decoder,
1322                offset + 0,
1323                _depth
1324            )?;
1325            fidl::decode!(
1326                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>>,
1327                fidl::encoding::DefaultFuchsiaResourceDialect,
1328                &mut self.network,
1329                decoder,
1330                offset + 16,
1331                _depth
1332            )?;
1333            Ok(())
1334        }
1335    }
1336
1337    impl fidl::encoding::ResourceTypeMarker for NetworkAddPortRequest {
1338        type Borrowed<'a> = &'a mut Self;
1339        fn take_or_borrow<'a>(
1340            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1341        ) -> Self::Borrowed<'a> {
1342            value
1343        }
1344    }
1345
1346    unsafe impl fidl::encoding::TypeMarker for NetworkAddPortRequest {
1347        type Owned = Self;
1348
1349        #[inline(always)]
1350        fn inline_align(_context: fidl::encoding::Context) -> usize {
1351            4
1352        }
1353
1354        #[inline(always)]
1355        fn inline_size(_context: fidl::encoding::Context) -> usize {
1356            8
1357        }
1358    }
1359
1360    unsafe impl
1361        fidl::encoding::Encode<NetworkAddPortRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1362        for &mut NetworkAddPortRequest
1363    {
1364        #[inline]
1365        unsafe fn encode(
1366            self,
1367            encoder: &mut fidl::encoding::Encoder<
1368                '_,
1369                fidl::encoding::DefaultFuchsiaResourceDialect,
1370            >,
1371            offset: usize,
1372            _depth: fidl::encoding::Depth,
1373        ) -> fidl::Result<()> {
1374            encoder.debug_check_bounds::<NetworkAddPortRequest>(offset);
1375            // Delegate to tuple encoding.
1376            fidl::encoding::Encode::<NetworkAddPortRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1377                (
1378                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.port),
1379                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.interface),
1380                ),
1381                encoder, offset, _depth
1382            )
1383        }
1384    }
1385    unsafe impl<
1386        T0: fidl::encoding::Encode<
1387                fidl::encoding::Endpoint<
1388                    fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1389                >,
1390                fidl::encoding::DefaultFuchsiaResourceDialect,
1391            >,
1392        T1: fidl::encoding::Encode<
1393                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>>,
1394                fidl::encoding::DefaultFuchsiaResourceDialect,
1395            >,
1396    >
1397        fidl::encoding::Encode<NetworkAddPortRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1398        for (T0, T1)
1399    {
1400        #[inline]
1401        unsafe fn encode(
1402            self,
1403            encoder: &mut fidl::encoding::Encoder<
1404                '_,
1405                fidl::encoding::DefaultFuchsiaResourceDialect,
1406            >,
1407            offset: usize,
1408            depth: fidl::encoding::Depth,
1409        ) -> fidl::Result<()> {
1410            encoder.debug_check_bounds::<NetworkAddPortRequest>(offset);
1411            // Zero out padding regions. There's no need to apply masks
1412            // because the unmasked parts will be overwritten by fields.
1413            // Write the fields.
1414            self.0.encode(encoder, offset + 0, depth)?;
1415            self.1.encode(encoder, offset + 4, depth)?;
1416            Ok(())
1417        }
1418    }
1419
1420    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1421        for NetworkAddPortRequest
1422    {
1423        #[inline(always)]
1424        fn new_empty() -> Self {
1425            Self {
1426                port: fidl::new_empty!(
1427                    fidl::encoding::Endpoint<
1428                        fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1429                    >,
1430                    fidl::encoding::DefaultFuchsiaResourceDialect
1431                ),
1432                interface: fidl::new_empty!(
1433                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>>,
1434                    fidl::encoding::DefaultFuchsiaResourceDialect
1435                ),
1436            }
1437        }
1438
1439        #[inline]
1440        unsafe fn decode(
1441            &mut self,
1442            decoder: &mut fidl::encoding::Decoder<
1443                '_,
1444                fidl::encoding::DefaultFuchsiaResourceDialect,
1445            >,
1446            offset: usize,
1447            _depth: fidl::encoding::Depth,
1448        ) -> fidl::Result<()> {
1449            decoder.debug_check_bounds::<Self>(offset);
1450            // Verify that padding bytes are zero.
1451            fidl::decode!(
1452                fidl::encoding::Endpoint<
1453                    fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1454                >,
1455                fidl::encoding::DefaultFuchsiaResourceDialect,
1456                &mut self.port,
1457                decoder,
1458                offset + 0,
1459                _depth
1460            )?;
1461            fidl::decode!(
1462                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>>,
1463                fidl::encoding::DefaultFuchsiaResourceDialect,
1464                &mut self.interface,
1465                decoder,
1466                offset + 4,
1467                _depth
1468            )?;
1469            Ok(())
1470        }
1471    }
1472}