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__common::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
120pub mod control_ordinals {
121    pub const SET_ENABLED: u64 = 0x13b7914afdb709a6;
122}
123
124pub mod factory_ordinals {
125    pub const CREATE: u64 = 0x65f64a124fd0170e;
126}
127
128mod internal {
129    use super::*;
130    unsafe impl fidl::encoding::TypeMarker for Error {
131        type Owned = Self;
132
133        #[inline(always)]
134        fn inline_align(_context: fidl::encoding::Context) -> usize {
135            std::mem::align_of::<u32>()
136        }
137
138        #[inline(always)]
139        fn inline_size(_context: fidl::encoding::Context) -> usize {
140            std::mem::size_of::<u32>()
141        }
142
143        #[inline(always)]
144        fn encode_is_copy() -> bool {
145            false
146        }
147
148        #[inline(always)]
149        fn decode_is_copy() -> bool {
150            false
151        }
152    }
153
154    impl fidl::encoding::ValueTypeMarker for Error {
155        type Borrowed<'a> = Self;
156        #[inline(always)]
157        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
158            *value
159        }
160    }
161
162    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
163        #[inline]
164        unsafe fn encode(
165            self,
166            encoder: &mut fidl::encoding::Encoder<'_, D>,
167            offset: usize,
168            _depth: fidl::encoding::Depth,
169        ) -> fidl::Result<()> {
170            encoder.debug_check_bounds::<Self>(offset);
171            encoder.write_num(self.into_primitive(), offset);
172            Ok(())
173        }
174    }
175
176    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
177        #[inline(always)]
178        fn new_empty() -> Self {
179            Self::unknown()
180        }
181
182        #[inline]
183        unsafe fn decode(
184            &mut self,
185            decoder: &mut fidl::encoding::Decoder<'_, D>,
186            offset: usize,
187            _depth: fidl::encoding::Depth,
188        ) -> fidl::Result<()> {
189            decoder.debug_check_bounds::<Self>(offset);
190            let prim = decoder.read_num::<u32>(offset);
191
192            *self = Self::from_primitive_allow_unknown(prim);
193            Ok(())
194        }
195    }
196
197    impl fidl::encoding::ValueTypeMarker for ControlConfig {
198        type Borrowed<'a> = &'a Self;
199        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
200            value
201        }
202    }
203
204    unsafe impl fidl::encoding::TypeMarker for ControlConfig {
205        type Owned = Self;
206
207        #[inline(always)]
208        fn inline_align(_context: fidl::encoding::Context) -> usize {
209            8
210        }
211
212        #[inline(always)]
213        fn inline_size(_context: fidl::encoding::Context) -> usize {
214            32
215        }
216    }
217
218    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ControlConfig, D>
219        for &ControlConfig
220    {
221        #[inline]
222        unsafe fn encode(
223            self,
224            encoder: &mut fidl::encoding::Encoder<'_, D>,
225            offset: usize,
226            _depth: fidl::encoding::Depth,
227        ) -> fidl::Result<()> {
228            encoder.debug_check_bounds::<ControlConfig>(offset);
229            // Delegate to tuple encoding.
230            fidl::encoding::Encode::<ControlConfig, D>::encode(
231                (
232                    <fidl_fuchsia_net__common::Subnet as fidl::encoding::ValueTypeMarker>::borrow(
233                        &self.src_subnet,
234                    ),
235                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.output_interface),
236                ),
237                encoder,
238                offset,
239                _depth,
240            )
241        }
242    }
243    unsafe impl<
244            D: fidl::encoding::ResourceDialect,
245            T0: fidl::encoding::Encode<fidl_fuchsia_net__common::Subnet, D>,
246            T1: fidl::encoding::Encode<u64, D>,
247        > fidl::encoding::Encode<ControlConfig, D> for (T0, T1)
248    {
249        #[inline]
250        unsafe fn encode(
251            self,
252            encoder: &mut fidl::encoding::Encoder<'_, D>,
253            offset: usize,
254            depth: fidl::encoding::Depth,
255        ) -> fidl::Result<()> {
256            encoder.debug_check_bounds::<ControlConfig>(offset);
257            // Zero out padding regions. There's no need to apply masks
258            // because the unmasked parts will be overwritten by fields.
259            // Write the fields.
260            self.0.encode(encoder, offset + 0, depth)?;
261            self.1.encode(encoder, offset + 24, depth)?;
262            Ok(())
263        }
264    }
265
266    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ControlConfig {
267        #[inline(always)]
268        fn new_empty() -> Self {
269            Self {
270                src_subnet: fidl::new_empty!(fidl_fuchsia_net__common::Subnet, D),
271                output_interface: fidl::new_empty!(u64, D),
272            }
273        }
274
275        #[inline]
276        unsafe fn decode(
277            &mut self,
278            decoder: &mut fidl::encoding::Decoder<'_, D>,
279            offset: usize,
280            _depth: fidl::encoding::Depth,
281        ) -> fidl::Result<()> {
282            decoder.debug_check_bounds::<Self>(offset);
283            // Verify that padding bytes are zero.
284            fidl::decode!(
285                fidl_fuchsia_net__common::Subnet,
286                D,
287                &mut self.src_subnet,
288                decoder,
289                offset + 0,
290                _depth
291            )?;
292            fidl::decode!(u64, D, &mut self.output_interface, decoder, offset + 24, _depth)?;
293            Ok(())
294        }
295    }
296
297    impl fidl::encoding::ValueTypeMarker for ControlSetEnabledRequest {
298        type Borrowed<'a> = &'a Self;
299        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
300            value
301        }
302    }
303
304    unsafe impl fidl::encoding::TypeMarker for ControlSetEnabledRequest {
305        type Owned = Self;
306
307        #[inline(always)]
308        fn inline_align(_context: fidl::encoding::Context) -> usize {
309            1
310        }
311
312        #[inline(always)]
313        fn inline_size(_context: fidl::encoding::Context) -> usize {
314            1
315        }
316    }
317
318    unsafe impl<D: fidl::encoding::ResourceDialect>
319        fidl::encoding::Encode<ControlSetEnabledRequest, D> for &ControlSetEnabledRequest
320    {
321        #[inline]
322        unsafe fn encode(
323            self,
324            encoder: &mut fidl::encoding::Encoder<'_, D>,
325            offset: usize,
326            _depth: fidl::encoding::Depth,
327        ) -> fidl::Result<()> {
328            encoder.debug_check_bounds::<ControlSetEnabledRequest>(offset);
329            // Delegate to tuple encoding.
330            fidl::encoding::Encode::<ControlSetEnabledRequest, D>::encode(
331                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.enabled),),
332                encoder,
333                offset,
334                _depth,
335            )
336        }
337    }
338    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
339        fidl::encoding::Encode<ControlSetEnabledRequest, D> for (T0,)
340    {
341        #[inline]
342        unsafe fn encode(
343            self,
344            encoder: &mut fidl::encoding::Encoder<'_, D>,
345            offset: usize,
346            depth: fidl::encoding::Depth,
347        ) -> fidl::Result<()> {
348            encoder.debug_check_bounds::<ControlSetEnabledRequest>(offset);
349            // Zero out padding regions. There's no need to apply masks
350            // because the unmasked parts will be overwritten by fields.
351            // Write the fields.
352            self.0.encode(encoder, offset + 0, depth)?;
353            Ok(())
354        }
355    }
356
357    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
358        for ControlSetEnabledRequest
359    {
360        #[inline(always)]
361        fn new_empty() -> Self {
362            Self { enabled: fidl::new_empty!(bool, D) }
363        }
364
365        #[inline]
366        unsafe fn decode(
367            &mut self,
368            decoder: &mut fidl::encoding::Decoder<'_, D>,
369            offset: usize,
370            _depth: fidl::encoding::Depth,
371        ) -> fidl::Result<()> {
372            decoder.debug_check_bounds::<Self>(offset);
373            // Verify that padding bytes are zero.
374            fidl::decode!(bool, D, &mut self.enabled, decoder, offset + 0, _depth)?;
375            Ok(())
376        }
377    }
378
379    impl fidl::encoding::ValueTypeMarker for ControlSetEnabledResponse {
380        type Borrowed<'a> = &'a Self;
381        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
382            value
383        }
384    }
385
386    unsafe impl fidl::encoding::TypeMarker for ControlSetEnabledResponse {
387        type Owned = Self;
388
389        #[inline(always)]
390        fn inline_align(_context: fidl::encoding::Context) -> usize {
391            1
392        }
393
394        #[inline(always)]
395        fn inline_size(_context: fidl::encoding::Context) -> usize {
396            1
397        }
398    }
399
400    unsafe impl<D: fidl::encoding::ResourceDialect>
401        fidl::encoding::Encode<ControlSetEnabledResponse, D> for &ControlSetEnabledResponse
402    {
403        #[inline]
404        unsafe fn encode(
405            self,
406            encoder: &mut fidl::encoding::Encoder<'_, D>,
407            offset: usize,
408            _depth: fidl::encoding::Depth,
409        ) -> fidl::Result<()> {
410            encoder.debug_check_bounds::<ControlSetEnabledResponse>(offset);
411            // Delegate to tuple encoding.
412            fidl::encoding::Encode::<ControlSetEnabledResponse, D>::encode(
413                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.was_enabled),),
414                encoder,
415                offset,
416                _depth,
417            )
418        }
419    }
420    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
421        fidl::encoding::Encode<ControlSetEnabledResponse, D> for (T0,)
422    {
423        #[inline]
424        unsafe fn encode(
425            self,
426            encoder: &mut fidl::encoding::Encoder<'_, D>,
427            offset: usize,
428            depth: fidl::encoding::Depth,
429        ) -> fidl::Result<()> {
430            encoder.debug_check_bounds::<ControlSetEnabledResponse>(offset);
431            // Zero out padding regions. There's no need to apply masks
432            // because the unmasked parts will be overwritten by fields.
433            // Write the fields.
434            self.0.encode(encoder, offset + 0, depth)?;
435            Ok(())
436        }
437    }
438
439    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
440        for ControlSetEnabledResponse
441    {
442        #[inline(always)]
443        fn new_empty() -> Self {
444            Self { was_enabled: fidl::new_empty!(bool, D) }
445        }
446
447        #[inline]
448        unsafe fn decode(
449            &mut self,
450            decoder: &mut fidl::encoding::Decoder<'_, D>,
451            offset: usize,
452            _depth: fidl::encoding::Depth,
453        ) -> fidl::Result<()> {
454            decoder.debug_check_bounds::<Self>(offset);
455            // Verify that padding bytes are zero.
456            fidl::decode!(bool, D, &mut self.was_enabled, decoder, offset + 0, _depth)?;
457            Ok(())
458        }
459    }
460}