Skip to main content

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