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