fidl_fuchsia_net_masquerade_common/
fidl_fuchsia_net_masquerade_common.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::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// All possible error types that may be returned by calls to `Control` or `Factory`.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13pub enum Error {
14    /// An unsupported configuration was provided. For example, the provided
15    /// `src_subnet` was unspecified (`0/0`).
16    Unsupported,
17    /// One or more of the configuration fields was invalid (e.g. `src_if` is 0).
18    InvalidArguments,
19    /// The provided `src_if` was not found.
20    NotFound,
21    /// The provided `src_subnet`/`output_interface` pair already exist in the Nat
22    /// rules.
23    AlreadyExists,
24    /// The call to `fuchsia.net.filter.deprecated.Filter::UpdateNatRules`
25    /// returned `BadRule`.
26    BadRule,
27    /// The attempt to update the Nat rules failed with `GenerationMismatch` too
28    /// many times.
29    RetryExceeded,
30    #[doc(hidden)]
31    __SourceBreaking { unknown_ordinal: u32 },
32}
33
34/// Pattern that matches an unknown `Error` member.
35#[macro_export]
36macro_rules! ErrorUnknown {
37    () => {
38        _
39    };
40}
41
42impl Error {
43    #[inline]
44    pub fn from_primitive(prim: u32) -> Option<Self> {
45        match prim {
46            0 => Some(Self::Unsupported),
47            1 => Some(Self::InvalidArguments),
48            2 => Some(Self::NotFound),
49            3 => Some(Self::AlreadyExists),
50            4 => Some(Self::BadRule),
51            5 => Some(Self::RetryExceeded),
52            _ => None,
53        }
54    }
55
56    #[inline]
57    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
58        match prim {
59            0 => Self::Unsupported,
60            1 => Self::InvalidArguments,
61            2 => Self::NotFound,
62            3 => Self::AlreadyExists,
63            4 => Self::BadRule,
64            5 => Self::RetryExceeded,
65            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
66        }
67    }
68
69    #[inline]
70    pub fn unknown() -> Self {
71        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
72    }
73
74    #[inline]
75    pub const fn into_primitive(self) -> u32 {
76        match self {
77            Self::Unsupported => 0,
78            Self::InvalidArguments => 1,
79            Self::NotFound => 2,
80            Self::AlreadyExists => 3,
81            Self::BadRule => 4,
82            Self::RetryExceeded => 5,
83            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
84        }
85    }
86
87    #[inline]
88    pub fn is_unknown(&self) -> bool {
89        match self {
90            Self::__SourceBreaking { unknown_ordinal: _ } => true,
91            _ => false,
92        }
93    }
94}
95
96#[derive(Clone, Debug, PartialEq)]
97pub struct ControlConfig {
98    /// The network to be masqueraded.
99    pub src_subnet: fidl_fuchsia_net::Subnet,
100    /// The interface through which to masquerade.
101    pub output_interface: u64,
102}
103
104impl fidl::Persistable for ControlConfig {}
105
106#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
107pub struct ControlSetEnabledRequest {
108    pub enabled: bool,
109}
110
111impl fidl::Persistable for ControlSetEnabledRequest {}
112
113#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
114pub struct ControlSetEnabledResponse {
115    pub was_enabled: bool,
116}
117
118impl fidl::Persistable for ControlSetEnabledResponse {}
119
120mod internal {
121    use super::*;
122    unsafe impl fidl::encoding::TypeMarker for Error {
123        type Owned = Self;
124
125        #[inline(always)]
126        fn inline_align(_context: fidl::encoding::Context) -> usize {
127            std::mem::align_of::<u32>()
128        }
129
130        #[inline(always)]
131        fn inline_size(_context: fidl::encoding::Context) -> usize {
132            std::mem::size_of::<u32>()
133        }
134
135        #[inline(always)]
136        fn encode_is_copy() -> bool {
137            false
138        }
139
140        #[inline(always)]
141        fn decode_is_copy() -> bool {
142            false
143        }
144    }
145
146    impl fidl::encoding::ValueTypeMarker for Error {
147        type Borrowed<'a> = Self;
148        #[inline(always)]
149        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
150            *value
151        }
152    }
153
154    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
155        #[inline]
156        unsafe fn encode(
157            self,
158            encoder: &mut fidl::encoding::Encoder<'_, D>,
159            offset: usize,
160            _depth: fidl::encoding::Depth,
161        ) -> fidl::Result<()> {
162            encoder.debug_check_bounds::<Self>(offset);
163            encoder.write_num(self.into_primitive(), offset);
164            Ok(())
165        }
166    }
167
168    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
169        #[inline(always)]
170        fn new_empty() -> Self {
171            Self::unknown()
172        }
173
174        #[inline]
175        unsafe fn decode(
176            &mut self,
177            decoder: &mut fidl::encoding::Decoder<'_, D>,
178            offset: usize,
179            _depth: fidl::encoding::Depth,
180        ) -> fidl::Result<()> {
181            decoder.debug_check_bounds::<Self>(offset);
182            let prim = decoder.read_num::<u32>(offset);
183
184            *self = Self::from_primitive_allow_unknown(prim);
185            Ok(())
186        }
187    }
188
189    impl fidl::encoding::ValueTypeMarker for ControlConfig {
190        type Borrowed<'a> = &'a Self;
191        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
192            value
193        }
194    }
195
196    unsafe impl fidl::encoding::TypeMarker for ControlConfig {
197        type Owned = Self;
198
199        #[inline(always)]
200        fn inline_align(_context: fidl::encoding::Context) -> usize {
201            8
202        }
203
204        #[inline(always)]
205        fn inline_size(_context: fidl::encoding::Context) -> usize {
206            32
207        }
208    }
209
210    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ControlConfig, D>
211        for &ControlConfig
212    {
213        #[inline]
214        unsafe fn encode(
215            self,
216            encoder: &mut fidl::encoding::Encoder<'_, D>,
217            offset: usize,
218            _depth: fidl::encoding::Depth,
219        ) -> fidl::Result<()> {
220            encoder.debug_check_bounds::<ControlConfig>(offset);
221            // Delegate to tuple encoding.
222            fidl::encoding::Encode::<ControlConfig, D>::encode(
223                (
224                    <fidl_fuchsia_net::Subnet as fidl::encoding::ValueTypeMarker>::borrow(
225                        &self.src_subnet,
226                    ),
227                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.output_interface),
228                ),
229                encoder,
230                offset,
231                _depth,
232            )
233        }
234    }
235    unsafe impl<
236            D: fidl::encoding::ResourceDialect,
237            T0: fidl::encoding::Encode<fidl_fuchsia_net::Subnet, D>,
238            T1: fidl::encoding::Encode<u64, D>,
239        > fidl::encoding::Encode<ControlConfig, D> for (T0, T1)
240    {
241        #[inline]
242        unsafe fn encode(
243            self,
244            encoder: &mut fidl::encoding::Encoder<'_, D>,
245            offset: usize,
246            depth: fidl::encoding::Depth,
247        ) -> fidl::Result<()> {
248            encoder.debug_check_bounds::<ControlConfig>(offset);
249            // Zero out padding regions. There's no need to apply masks
250            // because the unmasked parts will be overwritten by fields.
251            // Write the fields.
252            self.0.encode(encoder, offset + 0, depth)?;
253            self.1.encode(encoder, offset + 24, depth)?;
254            Ok(())
255        }
256    }
257
258    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ControlConfig {
259        #[inline(always)]
260        fn new_empty() -> Self {
261            Self {
262                src_subnet: fidl::new_empty!(fidl_fuchsia_net::Subnet, D),
263                output_interface: fidl::new_empty!(u64, D),
264            }
265        }
266
267        #[inline]
268        unsafe fn decode(
269            &mut self,
270            decoder: &mut fidl::encoding::Decoder<'_, D>,
271            offset: usize,
272            _depth: fidl::encoding::Depth,
273        ) -> fidl::Result<()> {
274            decoder.debug_check_bounds::<Self>(offset);
275            // Verify that padding bytes are zero.
276            fidl::decode!(
277                fidl_fuchsia_net::Subnet,
278                D,
279                &mut self.src_subnet,
280                decoder,
281                offset + 0,
282                _depth
283            )?;
284            fidl::decode!(u64, D, &mut self.output_interface, decoder, offset + 24, _depth)?;
285            Ok(())
286        }
287    }
288
289    impl fidl::encoding::ValueTypeMarker for ControlSetEnabledRequest {
290        type Borrowed<'a> = &'a Self;
291        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
292            value
293        }
294    }
295
296    unsafe impl fidl::encoding::TypeMarker for ControlSetEnabledRequest {
297        type Owned = Self;
298
299        #[inline(always)]
300        fn inline_align(_context: fidl::encoding::Context) -> usize {
301            1
302        }
303
304        #[inline(always)]
305        fn inline_size(_context: fidl::encoding::Context) -> usize {
306            1
307        }
308    }
309
310    unsafe impl<D: fidl::encoding::ResourceDialect>
311        fidl::encoding::Encode<ControlSetEnabledRequest, D> for &ControlSetEnabledRequest
312    {
313        #[inline]
314        unsafe fn encode(
315            self,
316            encoder: &mut fidl::encoding::Encoder<'_, D>,
317            offset: usize,
318            _depth: fidl::encoding::Depth,
319        ) -> fidl::Result<()> {
320            encoder.debug_check_bounds::<ControlSetEnabledRequest>(offset);
321            // Delegate to tuple encoding.
322            fidl::encoding::Encode::<ControlSetEnabledRequest, D>::encode(
323                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.enabled),),
324                encoder,
325                offset,
326                _depth,
327            )
328        }
329    }
330    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
331        fidl::encoding::Encode<ControlSetEnabledRequest, D> for (T0,)
332    {
333        #[inline]
334        unsafe fn encode(
335            self,
336            encoder: &mut fidl::encoding::Encoder<'_, D>,
337            offset: usize,
338            depth: fidl::encoding::Depth,
339        ) -> fidl::Result<()> {
340            encoder.debug_check_bounds::<ControlSetEnabledRequest>(offset);
341            // Zero out padding regions. There's no need to apply masks
342            // because the unmasked parts will be overwritten by fields.
343            // Write the fields.
344            self.0.encode(encoder, offset + 0, depth)?;
345            Ok(())
346        }
347    }
348
349    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
350        for ControlSetEnabledRequest
351    {
352        #[inline(always)]
353        fn new_empty() -> Self {
354            Self { enabled: fidl::new_empty!(bool, D) }
355        }
356
357        #[inline]
358        unsafe fn decode(
359            &mut self,
360            decoder: &mut fidl::encoding::Decoder<'_, D>,
361            offset: usize,
362            _depth: fidl::encoding::Depth,
363        ) -> fidl::Result<()> {
364            decoder.debug_check_bounds::<Self>(offset);
365            // Verify that padding bytes are zero.
366            fidl::decode!(bool, D, &mut self.enabled, decoder, offset + 0, _depth)?;
367            Ok(())
368        }
369    }
370
371    impl fidl::encoding::ValueTypeMarker for ControlSetEnabledResponse {
372        type Borrowed<'a> = &'a Self;
373        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
374            value
375        }
376    }
377
378    unsafe impl fidl::encoding::TypeMarker for ControlSetEnabledResponse {
379        type Owned = Self;
380
381        #[inline(always)]
382        fn inline_align(_context: fidl::encoding::Context) -> usize {
383            1
384        }
385
386        #[inline(always)]
387        fn inline_size(_context: fidl::encoding::Context) -> usize {
388            1
389        }
390    }
391
392    unsafe impl<D: fidl::encoding::ResourceDialect>
393        fidl::encoding::Encode<ControlSetEnabledResponse, D> for &ControlSetEnabledResponse
394    {
395        #[inline]
396        unsafe fn encode(
397            self,
398            encoder: &mut fidl::encoding::Encoder<'_, D>,
399            offset: usize,
400            _depth: fidl::encoding::Depth,
401        ) -> fidl::Result<()> {
402            encoder.debug_check_bounds::<ControlSetEnabledResponse>(offset);
403            // Delegate to tuple encoding.
404            fidl::encoding::Encode::<ControlSetEnabledResponse, D>::encode(
405                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.was_enabled),),
406                encoder,
407                offset,
408                _depth,
409            )
410        }
411    }
412    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
413        fidl::encoding::Encode<ControlSetEnabledResponse, D> for (T0,)
414    {
415        #[inline]
416        unsafe fn encode(
417            self,
418            encoder: &mut fidl::encoding::Encoder<'_, D>,
419            offset: usize,
420            depth: fidl::encoding::Depth,
421        ) -> fidl::Result<()> {
422            encoder.debug_check_bounds::<ControlSetEnabledResponse>(offset);
423            // Zero out padding regions. There's no need to apply masks
424            // because the unmasked parts will be overwritten by fields.
425            // Write the fields.
426            self.0.encode(encoder, offset + 0, depth)?;
427            Ok(())
428        }
429    }
430
431    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
432        for ControlSetEnabledResponse
433    {
434        #[inline(always)]
435        fn new_empty() -> Self {
436            Self { was_enabled: fidl::new_empty!(bool, D) }
437        }
438
439        #[inline]
440        unsafe fn decode(
441            &mut self,
442            decoder: &mut fidl::encoding::Decoder<'_, D>,
443            offset: usize,
444            _depth: fidl::encoding::Depth,
445        ) -> fidl::Result<()> {
446            decoder.debug_check_bounds::<Self>(offset);
447            // Verify that padding bytes are zero.
448            fidl::decode!(bool, D, &mut self.was_enabled, decoder, offset + 0, _depth)?;
449            Ok(())
450        }
451    }
452}