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::Handle {
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    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
414        self.inner.shutdown_with_epitaph(status)
415    }
416
417    fn is_closed(&self) -> bool {
418        self.inner.channel().is_closed()
419    }
420    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
421        self.inner.channel().on_closed()
422    }
423
424    #[cfg(target_os = "fuchsia")]
425    fn signal_peer(
426        &self,
427        clear_mask: zx::Signals,
428        set_mask: zx::Signals,
429    ) -> Result<(), zx_status::Status> {
430        use fidl::Peered;
431        self.inner.channel().signal_peer(clear_mask, set_mask)
432    }
433}
434
435impl ControlControlHandle {}
436
437#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
438pub struct InterfaceMarker;
439
440impl fidl::endpoints::ProtocolMarker for InterfaceMarker {
441    type Proxy = InterfaceProxy;
442    type RequestStream = InterfaceRequestStream;
443    #[cfg(target_os = "fuchsia")]
444    type SynchronousProxy = InterfaceSynchronousProxy;
445
446    const DEBUG_NAME: &'static str = "(anonymous) Interface";
447}
448
449pub trait InterfaceProxyInterface: Send + Sync {}
450#[derive(Debug)]
451#[cfg(target_os = "fuchsia")]
452pub struct InterfaceSynchronousProxy {
453    client: fidl::client::sync::Client,
454}
455
456#[cfg(target_os = "fuchsia")]
457impl fidl::endpoints::SynchronousProxy for InterfaceSynchronousProxy {
458    type Proxy = InterfaceProxy;
459    type Protocol = InterfaceMarker;
460
461    fn from_channel(inner: fidl::Channel) -> Self {
462        Self::new(inner)
463    }
464
465    fn into_channel(self) -> fidl::Channel {
466        self.client.into_channel()
467    }
468
469    fn as_channel(&self) -> &fidl::Channel {
470        self.client.as_channel()
471    }
472}
473
474#[cfg(target_os = "fuchsia")]
475impl InterfaceSynchronousProxy {
476    pub fn new(channel: fidl::Channel) -> Self {
477        let protocol_name = <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
478        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
479    }
480
481    pub fn into_channel(self) -> fidl::Channel {
482        self.client.into_channel()
483    }
484
485    /// Waits until an event arrives and returns it. It is safe for other
486    /// threads to make concurrent requests while waiting for an event.
487    pub fn wait_for_event(
488        &self,
489        deadline: zx::MonotonicInstant,
490    ) -> Result<InterfaceEvent, fidl::Error> {
491        InterfaceEvent::decode(self.client.wait_for_event(deadline)?)
492    }
493}
494
495#[cfg(target_os = "fuchsia")]
496impl From<InterfaceSynchronousProxy> for zx::Handle {
497    fn from(value: InterfaceSynchronousProxy) -> Self {
498        value.into_channel().into()
499    }
500}
501
502#[cfg(target_os = "fuchsia")]
503impl From<fidl::Channel> for InterfaceSynchronousProxy {
504    fn from(value: fidl::Channel) -> Self {
505        Self::new(value)
506    }
507}
508
509#[cfg(target_os = "fuchsia")]
510impl fidl::endpoints::FromClient for InterfaceSynchronousProxy {
511    type Protocol = InterfaceMarker;
512
513    fn from_client(value: fidl::endpoints::ClientEnd<InterfaceMarker>) -> Self {
514        Self::new(value.into_channel())
515    }
516}
517
518#[derive(Debug, Clone)]
519pub struct InterfaceProxy {
520    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
521}
522
523impl fidl::endpoints::Proxy for InterfaceProxy {
524    type Protocol = InterfaceMarker;
525
526    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
527        Self::new(inner)
528    }
529
530    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
531        self.client.into_channel().map_err(|client| Self { client })
532    }
533
534    fn as_channel(&self) -> &::fidl::AsyncChannel {
535        self.client.as_channel()
536    }
537}
538
539impl InterfaceProxy {
540    /// Create a new Proxy for fuchsia.net.virtualization/Interface.
541    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
542        let protocol_name = <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
543        Self { client: fidl::client::Client::new(channel, protocol_name) }
544    }
545
546    /// Get a Stream of events from the remote end of the protocol.
547    ///
548    /// # Panics
549    ///
550    /// Panics if the event stream was already taken.
551    pub fn take_event_stream(&self) -> InterfaceEventStream {
552        InterfaceEventStream { event_receiver: self.client.take_event_receiver() }
553    }
554}
555
556impl InterfaceProxyInterface for InterfaceProxy {}
557
558pub struct InterfaceEventStream {
559    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
560}
561
562impl std::marker::Unpin for InterfaceEventStream {}
563
564impl futures::stream::FusedStream for InterfaceEventStream {
565    fn is_terminated(&self) -> bool {
566        self.event_receiver.is_terminated()
567    }
568}
569
570impl futures::Stream for InterfaceEventStream {
571    type Item = Result<InterfaceEvent, fidl::Error>;
572
573    fn poll_next(
574        mut self: std::pin::Pin<&mut Self>,
575        cx: &mut std::task::Context<'_>,
576    ) -> std::task::Poll<Option<Self::Item>> {
577        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
578            &mut self.event_receiver,
579            cx
580        )?) {
581            Some(buf) => std::task::Poll::Ready(Some(InterfaceEvent::decode(buf))),
582            None => std::task::Poll::Ready(None),
583        }
584    }
585}
586
587#[derive(Debug)]
588pub enum InterfaceEvent {
589    OnRemoved { reason: InterfaceRemovalReason },
590}
591
592impl InterfaceEvent {
593    #[allow(irrefutable_let_patterns)]
594    pub fn into_on_removed(self) -> Option<InterfaceRemovalReason> {
595        if let InterfaceEvent::OnRemoved { reason } = self {
596            Some((reason))
597        } else {
598            None
599        }
600    }
601
602    /// Decodes a message buffer as a [`InterfaceEvent`].
603    fn decode(
604        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
605    ) -> Result<InterfaceEvent, fidl::Error> {
606        let (bytes, _handles) = buf.split_mut();
607        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
608        debug_assert_eq!(tx_header.tx_id, 0);
609        match tx_header.ordinal {
610            0x4785571ae39a2617 => {
611                let mut out = fidl::new_empty!(
612                    InterfaceOnRemovedRequest,
613                    fidl::encoding::DefaultFuchsiaResourceDialect
614                );
615                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InterfaceOnRemovedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
616                Ok((InterfaceEvent::OnRemoved { reason: out.reason }))
617            }
618            _ => Err(fidl::Error::UnknownOrdinal {
619                ordinal: tx_header.ordinal,
620                protocol_name: <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
621            }),
622        }
623    }
624}
625
626/// A Stream of incoming requests for fuchsia.net.virtualization/Interface.
627pub struct InterfaceRequestStream {
628    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
629    is_terminated: bool,
630}
631
632impl std::marker::Unpin for InterfaceRequestStream {}
633
634impl futures::stream::FusedStream for InterfaceRequestStream {
635    fn is_terminated(&self) -> bool {
636        self.is_terminated
637    }
638}
639
640impl fidl::endpoints::RequestStream for InterfaceRequestStream {
641    type Protocol = InterfaceMarker;
642    type ControlHandle = InterfaceControlHandle;
643
644    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
645        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
646    }
647
648    fn control_handle(&self) -> Self::ControlHandle {
649        InterfaceControlHandle { inner: self.inner.clone() }
650    }
651
652    fn into_inner(
653        self,
654    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
655    {
656        (self.inner, self.is_terminated)
657    }
658
659    fn from_inner(
660        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
661        is_terminated: bool,
662    ) -> Self {
663        Self { inner, is_terminated }
664    }
665}
666
667impl futures::Stream for InterfaceRequestStream {
668    type Item = Result<InterfaceRequest, fidl::Error>;
669
670    fn poll_next(
671        mut self: std::pin::Pin<&mut Self>,
672        cx: &mut std::task::Context<'_>,
673    ) -> std::task::Poll<Option<Self::Item>> {
674        let this = &mut *self;
675        if this.inner.check_shutdown(cx) {
676            this.is_terminated = true;
677            return std::task::Poll::Ready(None);
678        }
679        if this.is_terminated {
680            panic!("polled InterfaceRequestStream after completion");
681        }
682        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
683            |bytes, handles| {
684                match this.inner.channel().read_etc(cx, bytes, handles) {
685                    std::task::Poll::Ready(Ok(())) => {}
686                    std::task::Poll::Pending => return std::task::Poll::Pending,
687                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
688                        this.is_terminated = true;
689                        return std::task::Poll::Ready(None);
690                    }
691                    std::task::Poll::Ready(Err(e)) => {
692                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
693                            e.into(),
694                        ))))
695                    }
696                }
697
698                // A message has been received from the channel
699                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
700
701                std::task::Poll::Ready(Some(match header.ordinal {
702                    _ => Err(fidl::Error::UnknownOrdinal {
703                        ordinal: header.ordinal,
704                        protocol_name:
705                            <InterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
706                    }),
707                }))
708            },
709        )
710    }
711}
712
713/// Provides control over an interface.
714///
715/// This protocol encodes the lifetime of the underlying interface in both
716/// directions, that is:
717/// - if the client end is closed, the server will detach the interface
718///     from the network it belongs to and detach the network device;
719/// - if the server end is closed, the interface has been detached from
720///     the network it was attached to and destroyed.
721#[derive(Debug)]
722pub enum InterfaceRequest {}
723
724impl InterfaceRequest {
725    /// Name of the method defined in FIDL
726    pub fn method_name(&self) -> &'static str {
727        match *self {}
728    }
729}
730
731#[derive(Debug, Clone)]
732pub struct InterfaceControlHandle {
733    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
734}
735
736impl fidl::endpoints::ControlHandle for InterfaceControlHandle {
737    fn shutdown(&self) {
738        self.inner.shutdown()
739    }
740    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
741        self.inner.shutdown_with_epitaph(status)
742    }
743
744    fn is_closed(&self) -> bool {
745        self.inner.channel().is_closed()
746    }
747    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
748        self.inner.channel().on_closed()
749    }
750
751    #[cfg(target_os = "fuchsia")]
752    fn signal_peer(
753        &self,
754        clear_mask: zx::Signals,
755        set_mask: zx::Signals,
756    ) -> Result<(), zx_status::Status> {
757        use fidl::Peered;
758        self.inner.channel().signal_peer(clear_mask, set_mask)
759    }
760}
761
762impl InterfaceControlHandle {
763    pub fn send_on_removed(&self, mut reason: InterfaceRemovalReason) -> Result<(), fidl::Error> {
764        self.inner.send::<InterfaceOnRemovedRequest>(
765            (reason,),
766            0,
767            0x4785571ae39a2617,
768            fidl::encoding::DynamicFlags::empty(),
769        )
770    }
771}
772
773#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
774pub struct NetworkMarker;
775
776impl fidl::endpoints::ProtocolMarker for NetworkMarker {
777    type Proxy = NetworkProxy;
778    type RequestStream = NetworkRequestStream;
779    #[cfg(target_os = "fuchsia")]
780    type SynchronousProxy = NetworkSynchronousProxy;
781
782    const DEBUG_NAME: &'static str = "(anonymous) Network";
783}
784
785pub trait NetworkProxyInterface: Send + Sync {
786    fn r#add_port(
787        &self,
788        port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
789        interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
790    ) -> Result<(), fidl::Error>;
791}
792#[derive(Debug)]
793#[cfg(target_os = "fuchsia")]
794pub struct NetworkSynchronousProxy {
795    client: fidl::client::sync::Client,
796}
797
798#[cfg(target_os = "fuchsia")]
799impl fidl::endpoints::SynchronousProxy for NetworkSynchronousProxy {
800    type Proxy = NetworkProxy;
801    type Protocol = NetworkMarker;
802
803    fn from_channel(inner: fidl::Channel) -> Self {
804        Self::new(inner)
805    }
806
807    fn into_channel(self) -> fidl::Channel {
808        self.client.into_channel()
809    }
810
811    fn as_channel(&self) -> &fidl::Channel {
812        self.client.as_channel()
813    }
814}
815
816#[cfg(target_os = "fuchsia")]
817impl NetworkSynchronousProxy {
818    pub fn new(channel: fidl::Channel) -> Self {
819        let protocol_name = <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
820        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
821    }
822
823    pub fn into_channel(self) -> fidl::Channel {
824        self.client.into_channel()
825    }
826
827    /// Waits until an event arrives and returns it. It is safe for other
828    /// threads to make concurrent requests while waiting for an event.
829    pub fn wait_for_event(
830        &self,
831        deadline: zx::MonotonicInstant,
832    ) -> Result<NetworkEvent, fidl::Error> {
833        NetworkEvent::decode(self.client.wait_for_event(deadline)?)
834    }
835
836    /// Adds a port to the network.
837    ///
838    /// + request `port` port to be added.
839    /// + request `interface` provides control over the interface.
840    pub fn r#add_port(
841        &self,
842        mut port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
843        mut interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
844    ) -> Result<(), fidl::Error> {
845        self.client.send::<NetworkAddPortRequest>(
846            (port, interface),
847            0x7ad6a60c931a3f4e,
848            fidl::encoding::DynamicFlags::empty(),
849        )
850    }
851}
852
853#[cfg(target_os = "fuchsia")]
854impl From<NetworkSynchronousProxy> for zx::Handle {
855    fn from(value: NetworkSynchronousProxy) -> Self {
856        value.into_channel().into()
857    }
858}
859
860#[cfg(target_os = "fuchsia")]
861impl From<fidl::Channel> for NetworkSynchronousProxy {
862    fn from(value: fidl::Channel) -> Self {
863        Self::new(value)
864    }
865}
866
867#[cfg(target_os = "fuchsia")]
868impl fidl::endpoints::FromClient for NetworkSynchronousProxy {
869    type Protocol = NetworkMarker;
870
871    fn from_client(value: fidl::endpoints::ClientEnd<NetworkMarker>) -> Self {
872        Self::new(value.into_channel())
873    }
874}
875
876#[derive(Debug, Clone)]
877pub struct NetworkProxy {
878    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
879}
880
881impl fidl::endpoints::Proxy for NetworkProxy {
882    type Protocol = NetworkMarker;
883
884    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
885        Self::new(inner)
886    }
887
888    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
889        self.client.into_channel().map_err(|client| Self { client })
890    }
891
892    fn as_channel(&self) -> &::fidl::AsyncChannel {
893        self.client.as_channel()
894    }
895}
896
897impl NetworkProxy {
898    /// Create a new Proxy for fuchsia.net.virtualization/Network.
899    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
900        let protocol_name = <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
901        Self { client: fidl::client::Client::new(channel, protocol_name) }
902    }
903
904    /// Get a Stream of events from the remote end of the protocol.
905    ///
906    /// # Panics
907    ///
908    /// Panics if the event stream was already taken.
909    pub fn take_event_stream(&self) -> NetworkEventStream {
910        NetworkEventStream { event_receiver: self.client.take_event_receiver() }
911    }
912
913    /// Adds a port to the network.
914    ///
915    /// + request `port` port to be added.
916    /// + request `interface` provides control over the interface.
917    pub fn r#add_port(
918        &self,
919        mut port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
920        mut interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
921    ) -> Result<(), fidl::Error> {
922        NetworkProxyInterface::r#add_port(self, port, interface)
923    }
924}
925
926impl NetworkProxyInterface for NetworkProxy {
927    fn r#add_port(
928        &self,
929        mut port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
930        mut interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
931    ) -> Result<(), fidl::Error> {
932        self.client.send::<NetworkAddPortRequest>(
933            (port, interface),
934            0x7ad6a60c931a3f4e,
935            fidl::encoding::DynamicFlags::empty(),
936        )
937    }
938}
939
940pub struct NetworkEventStream {
941    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
942}
943
944impl std::marker::Unpin for NetworkEventStream {}
945
946impl futures::stream::FusedStream for NetworkEventStream {
947    fn is_terminated(&self) -> bool {
948        self.event_receiver.is_terminated()
949    }
950}
951
952impl futures::Stream for NetworkEventStream {
953    type Item = Result<NetworkEvent, fidl::Error>;
954
955    fn poll_next(
956        mut self: std::pin::Pin<&mut Self>,
957        cx: &mut std::task::Context<'_>,
958    ) -> std::task::Poll<Option<Self::Item>> {
959        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
960            &mut self.event_receiver,
961            cx
962        )?) {
963            Some(buf) => std::task::Poll::Ready(Some(NetworkEvent::decode(buf))),
964            None => std::task::Poll::Ready(None),
965        }
966    }
967}
968
969#[derive(Debug)]
970pub enum NetworkEvent {
971    OnRemoved { reason: NetworkRemovalReason },
972}
973
974impl NetworkEvent {
975    #[allow(irrefutable_let_patterns)]
976    pub fn into_on_removed(self) -> Option<NetworkRemovalReason> {
977        if let NetworkEvent::OnRemoved { reason } = self {
978            Some((reason))
979        } else {
980            None
981        }
982    }
983
984    /// Decodes a message buffer as a [`NetworkEvent`].
985    fn decode(
986        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
987    ) -> Result<NetworkEvent, fidl::Error> {
988        let (bytes, _handles) = buf.split_mut();
989        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
990        debug_assert_eq!(tx_header.tx_id, 0);
991        match tx_header.ordinal {
992            0xfe80656d1e5ec4a => {
993                let mut out = fidl::new_empty!(
994                    NetworkOnRemovedRequest,
995                    fidl::encoding::DefaultFuchsiaResourceDialect
996                );
997                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<NetworkOnRemovedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
998                Ok((NetworkEvent::OnRemoved { reason: out.reason }))
999            }
1000            _ => Err(fidl::Error::UnknownOrdinal {
1001                ordinal: tx_header.ordinal,
1002                protocol_name: <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1003            }),
1004        }
1005    }
1006}
1007
1008/// A Stream of incoming requests for fuchsia.net.virtualization/Network.
1009pub struct NetworkRequestStream {
1010    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1011    is_terminated: bool,
1012}
1013
1014impl std::marker::Unpin for NetworkRequestStream {}
1015
1016impl futures::stream::FusedStream for NetworkRequestStream {
1017    fn is_terminated(&self) -> bool {
1018        self.is_terminated
1019    }
1020}
1021
1022impl fidl::endpoints::RequestStream for NetworkRequestStream {
1023    type Protocol = NetworkMarker;
1024    type ControlHandle = NetworkControlHandle;
1025
1026    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1027        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1028    }
1029
1030    fn control_handle(&self) -> Self::ControlHandle {
1031        NetworkControlHandle { inner: self.inner.clone() }
1032    }
1033
1034    fn into_inner(
1035        self,
1036    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1037    {
1038        (self.inner, self.is_terminated)
1039    }
1040
1041    fn from_inner(
1042        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1043        is_terminated: bool,
1044    ) -> Self {
1045        Self { inner, is_terminated }
1046    }
1047}
1048
1049impl futures::Stream for NetworkRequestStream {
1050    type Item = Result<NetworkRequest, fidl::Error>;
1051
1052    fn poll_next(
1053        mut self: std::pin::Pin<&mut Self>,
1054        cx: &mut std::task::Context<'_>,
1055    ) -> std::task::Poll<Option<Self::Item>> {
1056        let this = &mut *self;
1057        if this.inner.check_shutdown(cx) {
1058            this.is_terminated = true;
1059            return std::task::Poll::Ready(None);
1060        }
1061        if this.is_terminated {
1062            panic!("polled NetworkRequestStream after completion");
1063        }
1064        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1065            |bytes, handles| {
1066                match this.inner.channel().read_etc(cx, bytes, handles) {
1067                    std::task::Poll::Ready(Ok(())) => {}
1068                    std::task::Poll::Pending => return std::task::Poll::Pending,
1069                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1070                        this.is_terminated = true;
1071                        return std::task::Poll::Ready(None);
1072                    }
1073                    std::task::Poll::Ready(Err(e)) => {
1074                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1075                            e.into(),
1076                        ))))
1077                    }
1078                }
1079
1080                // A message has been received from the channel
1081                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1082
1083                std::task::Poll::Ready(Some(match header.ordinal {
1084                    0x7ad6a60c931a3f4e => {
1085                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1086                        let mut req = fidl::new_empty!(
1087                            NetworkAddPortRequest,
1088                            fidl::encoding::DefaultFuchsiaResourceDialect
1089                        );
1090                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<NetworkAddPortRequest>(&header, _body_bytes, handles, &mut req)?;
1091                        let control_handle = NetworkControlHandle { inner: this.inner.clone() };
1092                        Ok(NetworkRequest::AddPort {
1093                            port: req.port,
1094                            interface: req.interface,
1095
1096                            control_handle,
1097                        })
1098                    }
1099                    _ => Err(fidl::Error::UnknownOrdinal {
1100                        ordinal: header.ordinal,
1101                        protocol_name:
1102                            <NetworkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1103                    }),
1104                }))
1105            },
1106        )
1107    }
1108}
1109
1110/// Provides control over a network.
1111///
1112/// This protocol encodes the lifetime of the underlying network in both
1113/// directions, that is:
1114/// - if the client end is closed: all interfaces added to the network
1115///     (not including any used to provide upstream connectivity) will be
1116///     removed and destroyed, and the network will be removed;
1117/// - if the server end is closed, all interfaces on the network and the
1118///     network itself have been destroyed.
1119#[derive(Debug)]
1120pub enum NetworkRequest {
1121    /// Adds a port to the network.
1122    ///
1123    /// + request `port` port to be added.
1124    /// + request `interface` provides control over the interface.
1125    AddPort {
1126        port: fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1127        interface: fidl::endpoints::ServerEnd<InterfaceMarker>,
1128        control_handle: NetworkControlHandle,
1129    },
1130}
1131
1132impl NetworkRequest {
1133    #[allow(irrefutable_let_patterns)]
1134    pub fn into_add_port(
1135        self,
1136    ) -> Option<(
1137        fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1138        fidl::endpoints::ServerEnd<InterfaceMarker>,
1139        NetworkControlHandle,
1140    )> {
1141        if let NetworkRequest::AddPort { port, interface, control_handle } = self {
1142            Some((port, interface, control_handle))
1143        } else {
1144            None
1145        }
1146    }
1147
1148    /// Name of the method defined in FIDL
1149    pub fn method_name(&self) -> &'static str {
1150        match *self {
1151            NetworkRequest::AddPort { .. } => "add_port",
1152        }
1153    }
1154}
1155
1156#[derive(Debug, Clone)]
1157pub struct NetworkControlHandle {
1158    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1159}
1160
1161impl fidl::endpoints::ControlHandle for NetworkControlHandle {
1162    fn shutdown(&self) {
1163        self.inner.shutdown()
1164    }
1165    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1166        self.inner.shutdown_with_epitaph(status)
1167    }
1168
1169    fn is_closed(&self) -> bool {
1170        self.inner.channel().is_closed()
1171    }
1172    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1173        self.inner.channel().on_closed()
1174    }
1175
1176    #[cfg(target_os = "fuchsia")]
1177    fn signal_peer(
1178        &self,
1179        clear_mask: zx::Signals,
1180        set_mask: zx::Signals,
1181    ) -> Result<(), zx_status::Status> {
1182        use fidl::Peered;
1183        self.inner.channel().signal_peer(clear_mask, set_mask)
1184    }
1185}
1186
1187impl NetworkControlHandle {
1188    pub fn send_on_removed(&self, mut reason: NetworkRemovalReason) -> Result<(), fidl::Error> {
1189        self.inner.send::<NetworkOnRemovedRequest>(
1190            (reason,),
1191            0,
1192            0xfe80656d1e5ec4a,
1193            fidl::encoding::DynamicFlags::empty(),
1194        )
1195    }
1196}
1197
1198mod internal {
1199    use super::*;
1200
1201    impl fidl::encoding::ResourceTypeMarker for ControlCreateNetworkRequest {
1202        type Borrowed<'a> = &'a mut Self;
1203        fn take_or_borrow<'a>(
1204            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1205        ) -> Self::Borrowed<'a> {
1206            value
1207        }
1208    }
1209
1210    unsafe impl fidl::encoding::TypeMarker for ControlCreateNetworkRequest {
1211        type Owned = Self;
1212
1213        #[inline(always)]
1214        fn inline_align(_context: fidl::encoding::Context) -> usize {
1215            8
1216        }
1217
1218        #[inline(always)]
1219        fn inline_size(_context: fidl::encoding::Context) -> usize {
1220            24
1221        }
1222    }
1223
1224    unsafe impl
1225        fidl::encoding::Encode<
1226            ControlCreateNetworkRequest,
1227            fidl::encoding::DefaultFuchsiaResourceDialect,
1228        > for &mut ControlCreateNetworkRequest
1229    {
1230        #[inline]
1231        unsafe fn encode(
1232            self,
1233            encoder: &mut fidl::encoding::Encoder<
1234                '_,
1235                fidl::encoding::DefaultFuchsiaResourceDialect,
1236            >,
1237            offset: usize,
1238            _depth: fidl::encoding::Depth,
1239        ) -> fidl::Result<()> {
1240            encoder.debug_check_bounds::<ControlCreateNetworkRequest>(offset);
1241            // Delegate to tuple encoding.
1242            fidl::encoding::Encode::<ControlCreateNetworkRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1243                (
1244                    <Config as fidl::encoding::ValueTypeMarker>::borrow(&self.config),
1245                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.network),
1246                ),
1247                encoder, offset, _depth
1248            )
1249        }
1250    }
1251    unsafe impl<
1252            T0: fidl::encoding::Encode<Config, fidl::encoding::DefaultFuchsiaResourceDialect>,
1253            T1: fidl::encoding::Encode<
1254                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>>,
1255                fidl::encoding::DefaultFuchsiaResourceDialect,
1256            >,
1257        >
1258        fidl::encoding::Encode<
1259            ControlCreateNetworkRequest,
1260            fidl::encoding::DefaultFuchsiaResourceDialect,
1261        > for (T0, T1)
1262    {
1263        #[inline]
1264        unsafe fn encode(
1265            self,
1266            encoder: &mut fidl::encoding::Encoder<
1267                '_,
1268                fidl::encoding::DefaultFuchsiaResourceDialect,
1269            >,
1270            offset: usize,
1271            depth: fidl::encoding::Depth,
1272        ) -> fidl::Result<()> {
1273            encoder.debug_check_bounds::<ControlCreateNetworkRequest>(offset);
1274            // Zero out padding regions. There's no need to apply masks
1275            // because the unmasked parts will be overwritten by fields.
1276            unsafe {
1277                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1278                (ptr as *mut u64).write_unaligned(0);
1279            }
1280            // Write the fields.
1281            self.0.encode(encoder, offset + 0, depth)?;
1282            self.1.encode(encoder, offset + 16, depth)?;
1283            Ok(())
1284        }
1285    }
1286
1287    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1288        for ControlCreateNetworkRequest
1289    {
1290        #[inline(always)]
1291        fn new_empty() -> Self {
1292            Self {
1293                config: fidl::new_empty!(Config, fidl::encoding::DefaultFuchsiaResourceDialect),
1294                network: fidl::new_empty!(
1295                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>>,
1296                    fidl::encoding::DefaultFuchsiaResourceDialect
1297                ),
1298            }
1299        }
1300
1301        #[inline]
1302        unsafe fn decode(
1303            &mut self,
1304            decoder: &mut fidl::encoding::Decoder<
1305                '_,
1306                fidl::encoding::DefaultFuchsiaResourceDialect,
1307            >,
1308            offset: usize,
1309            _depth: fidl::encoding::Depth,
1310        ) -> fidl::Result<()> {
1311            decoder.debug_check_bounds::<Self>(offset);
1312            // Verify that padding bytes are zero.
1313            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1314            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1315            let mask = 0xffffffff00000000u64;
1316            let maskedval = padval & mask;
1317            if maskedval != 0 {
1318                return Err(fidl::Error::NonZeroPadding {
1319                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1320                });
1321            }
1322            fidl::decode!(
1323                Config,
1324                fidl::encoding::DefaultFuchsiaResourceDialect,
1325                &mut self.config,
1326                decoder,
1327                offset + 0,
1328                _depth
1329            )?;
1330            fidl::decode!(
1331                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<NetworkMarker>>,
1332                fidl::encoding::DefaultFuchsiaResourceDialect,
1333                &mut self.network,
1334                decoder,
1335                offset + 16,
1336                _depth
1337            )?;
1338            Ok(())
1339        }
1340    }
1341
1342    impl fidl::encoding::ResourceTypeMarker for NetworkAddPortRequest {
1343        type Borrowed<'a> = &'a mut Self;
1344        fn take_or_borrow<'a>(
1345            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1346        ) -> Self::Borrowed<'a> {
1347            value
1348        }
1349    }
1350
1351    unsafe impl fidl::encoding::TypeMarker for NetworkAddPortRequest {
1352        type Owned = Self;
1353
1354        #[inline(always)]
1355        fn inline_align(_context: fidl::encoding::Context) -> usize {
1356            4
1357        }
1358
1359        #[inline(always)]
1360        fn inline_size(_context: fidl::encoding::Context) -> usize {
1361            8
1362        }
1363    }
1364
1365    unsafe impl
1366        fidl::encoding::Encode<NetworkAddPortRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1367        for &mut NetworkAddPortRequest
1368    {
1369        #[inline]
1370        unsafe fn encode(
1371            self,
1372            encoder: &mut fidl::encoding::Encoder<
1373                '_,
1374                fidl::encoding::DefaultFuchsiaResourceDialect,
1375            >,
1376            offset: usize,
1377            _depth: fidl::encoding::Depth,
1378        ) -> fidl::Result<()> {
1379            encoder.debug_check_bounds::<NetworkAddPortRequest>(offset);
1380            // Delegate to tuple encoding.
1381            fidl::encoding::Encode::<NetworkAddPortRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1382                (
1383                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.port),
1384                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.interface),
1385                ),
1386                encoder, offset, _depth
1387            )
1388        }
1389    }
1390    unsafe impl<
1391            T0: fidl::encoding::Encode<
1392                fidl::encoding::Endpoint<
1393                    fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1394                >,
1395                fidl::encoding::DefaultFuchsiaResourceDialect,
1396            >,
1397            T1: fidl::encoding::Encode<
1398                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>>,
1399                fidl::encoding::DefaultFuchsiaResourceDialect,
1400            >,
1401        >
1402        fidl::encoding::Encode<NetworkAddPortRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1403        for (T0, T1)
1404    {
1405        #[inline]
1406        unsafe fn encode(
1407            self,
1408            encoder: &mut fidl::encoding::Encoder<
1409                '_,
1410                fidl::encoding::DefaultFuchsiaResourceDialect,
1411            >,
1412            offset: usize,
1413            depth: fidl::encoding::Depth,
1414        ) -> fidl::Result<()> {
1415            encoder.debug_check_bounds::<NetworkAddPortRequest>(offset);
1416            // Zero out padding regions. There's no need to apply masks
1417            // because the unmasked parts will be overwritten by fields.
1418            // Write the fields.
1419            self.0.encode(encoder, offset + 0, depth)?;
1420            self.1.encode(encoder, offset + 4, depth)?;
1421            Ok(())
1422        }
1423    }
1424
1425    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1426        for NetworkAddPortRequest
1427    {
1428        #[inline(always)]
1429        fn new_empty() -> Self {
1430            Self {
1431                port: fidl::new_empty!(
1432                    fidl::encoding::Endpoint<
1433                        fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1434                    >,
1435                    fidl::encoding::DefaultFuchsiaResourceDialect
1436                ),
1437                interface: fidl::new_empty!(
1438                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>>,
1439                    fidl::encoding::DefaultFuchsiaResourceDialect
1440                ),
1441            }
1442        }
1443
1444        #[inline]
1445        unsafe fn decode(
1446            &mut self,
1447            decoder: &mut fidl::encoding::Decoder<
1448                '_,
1449                fidl::encoding::DefaultFuchsiaResourceDialect,
1450            >,
1451            offset: usize,
1452            _depth: fidl::encoding::Depth,
1453        ) -> fidl::Result<()> {
1454            decoder.debug_check_bounds::<Self>(offset);
1455            // Verify that padding bytes are zero.
1456            fidl::decode!(
1457                fidl::encoding::Endpoint<
1458                    fidl::endpoints::ClientEnd<fidl_fuchsia_hardware_network::PortMarker>,
1459                >,
1460                fidl::encoding::DefaultFuchsiaResourceDialect,
1461                &mut self.port,
1462                decoder,
1463                offset + 0,
1464                _depth
1465            )?;
1466            fidl::decode!(
1467                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<InterfaceMarker>>,
1468                fidl::encoding::DefaultFuchsiaResourceDialect,
1469                &mut self.interface,
1470                decoder,
1471                offset + 4,
1472                _depth
1473            )?;
1474            Ok(())
1475        }
1476    }
1477}