Skip to main content

fidl_fuchsia_net_common/
fidl_fuchsia_net_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/// A hostname.
12///
13/// Although the maximum length of a domain or hostname is 255 characters,
14/// each label within a name must not be longer than 63 characters as per
15/// [RFC 1035 section 2.3.4](https://tools.ietf.org/html/rfc1035#section-2.3.4).
16/// A label in a host name is the alphanumeric characters or hyphens, seperated
17/// by a period (e.g. abc.com has two labels, 'abc' and 'com').
18pub type Hostname = String;
19
20/// A unique non-zero interface identifier.
21pub type InterfaceId = u64;
22
23/// A mark that is used to make route decisions and can be attached to packets.
24pub type Mark = u32;
25
26/// The metric of a route. Lower metrics indicate higher priority.
27pub type RouteMetric = u32;
28
29/// Fuchsia does not have UIDs, we use the `MARK_2` domain mark to store the
30/// UID of the process that created the sockets when the socket was created
31/// by a process running in Starnix. This mark should be left unset otherwise.
32pub const MARK_DOMAIN_SOCKET_UID: MarkDomain = MarkDomain::Mark2;
33
34/// `MARK_1` domain is used to store the `SO_MARK` value set by Starnix
35/// processes. If a mark in this domain is absent, it will be reported to
36/// applications as a `0` since that is the default mark value on Linux.
37pub const MARK_DOMAIN_SO_MARK: MarkDomain = MarkDomain::Mark1;
38
39/// The maximum length of a hostname, as per
40/// [RFC 1035 section 2.3.4](https://tools.ietf.org/html/rfc1035#section-2.3.4).
41pub const MAX_HOSTNAME_SIZE: u64 = 255;
42
43/// IpVersion is an IP version.
44#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
45#[repr(u32)]
46pub enum IpVersion {
47    V4 = 1,
48    V6 = 2,
49}
50
51impl IpVersion {
52    #[inline]
53    pub fn from_primitive(prim: u32) -> Option<Self> {
54        match prim {
55            1 => Some(Self::V4),
56            2 => Some(Self::V6),
57            _ => None,
58        }
59    }
60
61    #[inline]
62    pub const fn into_primitive(self) -> u32 {
63        self as u32
64    }
65}
66
67/// Domains for a mark. This allows multiple marks to be set and retrieved
68/// independently.
69#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
70#[repr(u8)]
71pub enum MarkDomain {
72    Mark1 = 1,
73    Mark2 = 2,
74}
75
76impl MarkDomain {
77    #[inline]
78    pub fn from_primitive(prim: u8) -> Option<Self> {
79        match prim {
80            1 => Some(Self::Mark1),
81            2 => Some(Self::Mark2),
82            _ => None,
83        }
84    }
85
86    #[inline]
87    pub const fn into_primitive(self) -> u8 {
88        self as u8
89    }
90}
91
92/// Ipv4Address is expressed in network byte order, so the most significant byte
93/// ("127" in the address "127.0.0.1") will be at index 0.
94#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
95#[repr(C)]
96pub struct Ipv4Address {
97    pub addr: [u8; 4],
98}
99
100impl fidl::Persistable for Ipv4Address {}
101impl std::fmt::Debug for Ipv4Address {
102    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
103        f.debug_struct("Ipv4Address")
104            .field("addr", &fidl::marker::SensitiveDebug(&self.addr))
105            .finish()
106    }
107}
108
109/// An IPv4 address with its subnet prefix length.
110#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
111#[repr(C)]
112pub struct Ipv4AddressWithPrefix {
113    /// The IPv4 address.
114    pub addr: Ipv4Address,
115    /// The prefix length. Must be in the range [0, 32].
116    pub prefix_len: u8,
117}
118
119impl fidl::Persistable for Ipv4AddressWithPrefix {}
120
121/// An IPv4 socket address, composed of an IPv4 address and a port.
122///
123/// Inspired by the address definition in the [POSIX specification].
124///
125/// [POSIX specification]: https://pubs.opengroup.org/onlinepubs/9699919799/
126#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
127#[repr(C)]
128pub struct Ipv4SocketAddress {
129    /// IPv4 Address.
130    pub address: Ipv4Address,
131    /// Transport-layer port.
132    pub port: u16,
133}
134
135impl fidl::Persistable for Ipv4SocketAddress {}
136
137/// Ipv6Address is expressed in network byte order, so the most significant byte
138/// ("ff" in the address "ff02::1") will be at index 0.
139#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
140#[repr(C)]
141pub struct Ipv6Address {
142    pub addr: [u8; 16],
143}
144
145impl fidl::Persistable for Ipv6Address {}
146impl std::fmt::Debug for Ipv6Address {
147    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
148        f.debug_struct("Ipv6Address")
149            .field("addr", &fidl::marker::SensitiveDebug(&self.addr))
150            .finish()
151    }
152}
153
154/// An IPv6 address with its subnet prefix length.
155#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
156#[repr(C)]
157pub struct Ipv6AddressWithPrefix {
158    /// The IPv6 address.
159    pub addr: Ipv6Address,
160    /// The prefix length. Must be in the range [0, 128].
161    pub prefix_len: u8,
162}
163
164impl fidl::Persistable for Ipv6AddressWithPrefix {}
165
166/// An IPV6 socket address, composed of an IPv6 address, a port, and a scope identifier.
167///
168/// Inspired by the address definition in the [POSIX specification].
169///
170/// [POSIX specification]: https://pubs.opengroup.org/onlinepubs/9699919799/
171#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
172#[repr(C)]
173pub struct Ipv6SocketAddress {
174    /// IPv6 Address.
175    pub address: Ipv6Address,
176    /// Transport-layer port.
177    pub port: u16,
178    /// Provides a means to identify to which zone a non-global address belongs.
179    ///
180    /// A node may have interfaces attached to different zones of the same scope, for example
181    /// different link-local zones are disambiguated by the use of a `zone_index` providing the
182    /// interface identifier.
183    ///
184    /// `zone_index` 0 is the default zone.
185    ///
186    /// See [RFC 4007] for terminology and examples.
187    ///
188    /// [RFC 4007]: https://tools.ietf.org/html/rfc4007
189    pub zone_index: u64,
190}
191
192impl fidl::Persistable for Ipv6SocketAddress {}
193
194/// A MAC address used to identify a network interface on the data link layer within the network.
195#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
196#[repr(C)]
197pub struct MacAddress {
198    pub octets: [u8; 6],
199}
200
201impl fidl::Persistable for MacAddress {}
202impl std::fmt::Debug for MacAddress {
203    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
204        f.debug_struct("MacAddress")
205            .field("octets", &fidl::marker::SensitiveDebug(&self.octets))
206            .finish()
207    }
208}
209
210/// An IP address with its subnet prefix length.
211#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
212pub struct Subnet {
213    /// The IPv4 or IPv6 address.
214    pub addr: IpAddress,
215    /// The number of bits set to 1 in the subnet mask.
216    ///
217    /// When [`addr`] is [`IpAddress.ipv4`], must be in the range `[0, 32]`.
218    /// When [`addr`] is [`IpAddress.ipv6`], must be in the range `[0, 128]`.
219    pub prefix_len: u8,
220}
221
222impl fidl::Persistable for Subnet {}
223
224/// Includes all the marks the platform supports.
225#[derive(Clone, Debug, Default, PartialEq)]
226pub struct Marks {
227    /// The mark in the `MARK_1` domain.
228    pub mark_1: Option<u32>,
229    /// The mark in the `MARK_2` domain.
230    pub mark_2: Option<u32>,
231    #[doc(hidden)]
232    pub __source_breaking: fidl::marker::SourceBreaking,
233}
234
235impl fidl::Persistable for Marks {}
236
237/// Represents an IP address that may be either v4 or v6.
238#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
239pub enum IpAddress {
240    Ipv4(Ipv4Address),
241    Ipv6(Ipv6Address),
242}
243
244impl IpAddress {
245    #[inline]
246    pub fn ordinal(&self) -> u64 {
247        match *self {
248            Self::Ipv4(_) => 1,
249            Self::Ipv6(_) => 2,
250        }
251    }
252}
253
254impl fidl::Persistable for IpAddress {}
255
256/// Represents an IP socket address that may be either v4 or v6.
257#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
258pub enum SocketAddress {
259    Ipv4(Ipv4SocketAddress),
260    Ipv6(Ipv6SocketAddress),
261}
262
263impl SocketAddress {
264    #[inline]
265    pub fn ordinal(&self) -> u64 {
266        match *self {
267            Self::Ipv4(_) => 1,
268            Self::Ipv6(_) => 2,
269        }
270    }
271}
272
273impl fidl::Persistable for SocketAddress {}
274
275mod internal {
276    use super::*;
277    unsafe impl fidl::encoding::TypeMarker for IpVersion {
278        type Owned = Self;
279
280        #[inline(always)]
281        fn inline_align(_context: fidl::encoding::Context) -> usize {
282            std::mem::align_of::<u32>()
283        }
284
285        #[inline(always)]
286        fn inline_size(_context: fidl::encoding::Context) -> usize {
287            std::mem::size_of::<u32>()
288        }
289
290        #[inline(always)]
291        fn encode_is_copy() -> bool {
292            true
293        }
294
295        #[inline(always)]
296        fn decode_is_copy() -> bool {
297            false
298        }
299    }
300
301    impl fidl::encoding::ValueTypeMarker for IpVersion {
302        type Borrowed<'a> = Self;
303        #[inline(always)]
304        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
305            *value
306        }
307    }
308
309    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for IpVersion {
310        #[inline]
311        unsafe fn encode(
312            self,
313            encoder: &mut fidl::encoding::Encoder<'_, D>,
314            offset: usize,
315            _depth: fidl::encoding::Depth,
316        ) -> fidl::Result<()> {
317            encoder.debug_check_bounds::<Self>(offset);
318            encoder.write_num(self.into_primitive(), offset);
319            Ok(())
320        }
321    }
322
323    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for IpVersion {
324        #[inline(always)]
325        fn new_empty() -> Self {
326            Self::V4
327        }
328
329        #[inline]
330        unsafe fn decode(
331            &mut self,
332            decoder: &mut fidl::encoding::Decoder<'_, D>,
333            offset: usize,
334            _depth: fidl::encoding::Depth,
335        ) -> fidl::Result<()> {
336            decoder.debug_check_bounds::<Self>(offset);
337            let prim = decoder.read_num::<u32>(offset);
338
339            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
340            Ok(())
341        }
342    }
343    unsafe impl fidl::encoding::TypeMarker for MarkDomain {
344        type Owned = Self;
345
346        #[inline(always)]
347        fn inline_align(_context: fidl::encoding::Context) -> usize {
348            std::mem::align_of::<u8>()
349        }
350
351        #[inline(always)]
352        fn inline_size(_context: fidl::encoding::Context) -> usize {
353            std::mem::size_of::<u8>()
354        }
355
356        #[inline(always)]
357        fn encode_is_copy() -> bool {
358            true
359        }
360
361        #[inline(always)]
362        fn decode_is_copy() -> bool {
363            false
364        }
365    }
366
367    impl fidl::encoding::ValueTypeMarker for MarkDomain {
368        type Borrowed<'a> = Self;
369        #[inline(always)]
370        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
371            *value
372        }
373    }
374
375    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for MarkDomain {
376        #[inline]
377        unsafe fn encode(
378            self,
379            encoder: &mut fidl::encoding::Encoder<'_, D>,
380            offset: usize,
381            _depth: fidl::encoding::Depth,
382        ) -> fidl::Result<()> {
383            encoder.debug_check_bounds::<Self>(offset);
384            encoder.write_num(self.into_primitive(), offset);
385            Ok(())
386        }
387    }
388
389    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MarkDomain {
390        #[inline(always)]
391        fn new_empty() -> Self {
392            Self::Mark1
393        }
394
395        #[inline]
396        unsafe fn decode(
397            &mut self,
398            decoder: &mut fidl::encoding::Decoder<'_, D>,
399            offset: usize,
400            _depth: fidl::encoding::Depth,
401        ) -> fidl::Result<()> {
402            decoder.debug_check_bounds::<Self>(offset);
403            let prim = decoder.read_num::<u8>(offset);
404
405            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
406            Ok(())
407        }
408    }
409
410    impl fidl::encoding::ValueTypeMarker for Ipv4Address {
411        type Borrowed<'a> = &'a Self;
412        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
413            value
414        }
415    }
416
417    unsafe impl fidl::encoding::TypeMarker for Ipv4Address {
418        type Owned = Self;
419
420        #[inline(always)]
421        fn inline_align(_context: fidl::encoding::Context) -> usize {
422            1
423        }
424
425        #[inline(always)]
426        fn inline_size(_context: fidl::encoding::Context) -> usize {
427            4
428        }
429        #[inline(always)]
430        fn encode_is_copy() -> bool {
431            true
432        }
433
434        #[inline(always)]
435        fn decode_is_copy() -> bool {
436            true
437        }
438    }
439
440    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Ipv4Address, D>
441        for &Ipv4Address
442    {
443        #[inline]
444        unsafe fn encode(
445            self,
446            encoder: &mut fidl::encoding::Encoder<'_, D>,
447            offset: usize,
448            _depth: fidl::encoding::Depth,
449        ) -> fidl::Result<()> {
450            encoder.debug_check_bounds::<Ipv4Address>(offset);
451            unsafe {
452                // Copy the object into the buffer.
453                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
454                (buf_ptr as *mut Ipv4Address).write_unaligned((self as *const Ipv4Address).read());
455                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
456                // done second because the memcpy will write garbage to these bytes.
457            }
458            Ok(())
459        }
460    }
461    unsafe impl<
462        D: fidl::encoding::ResourceDialect,
463        T0: fidl::encoding::Encode<fidl::encoding::Array<u8, 4>, D>,
464    > fidl::encoding::Encode<Ipv4Address, D> for (T0,)
465    {
466        #[inline]
467        unsafe fn encode(
468            self,
469            encoder: &mut fidl::encoding::Encoder<'_, D>,
470            offset: usize,
471            depth: fidl::encoding::Depth,
472        ) -> fidl::Result<()> {
473            encoder.debug_check_bounds::<Ipv4Address>(offset);
474            // Zero out padding regions. There's no need to apply masks
475            // because the unmasked parts will be overwritten by fields.
476            // Write the fields.
477            self.0.encode(encoder, offset + 0, depth)?;
478            Ok(())
479        }
480    }
481
482    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Ipv4Address {
483        #[inline(always)]
484        fn new_empty() -> Self {
485            Self { addr: fidl::new_empty!(fidl::encoding::Array<u8, 4>, D) }
486        }
487
488        #[inline]
489        unsafe fn decode(
490            &mut self,
491            decoder: &mut fidl::encoding::Decoder<'_, D>,
492            offset: usize,
493            _depth: fidl::encoding::Depth,
494        ) -> fidl::Result<()> {
495            decoder.debug_check_bounds::<Self>(offset);
496            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
497            // Verify that padding bytes are zero.
498            // Copy from the buffer into the object.
499            unsafe {
500                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 4);
501            }
502            Ok(())
503        }
504    }
505
506    impl fidl::encoding::ValueTypeMarker for Ipv4AddressWithPrefix {
507        type Borrowed<'a> = &'a Self;
508        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
509            value
510        }
511    }
512
513    unsafe impl fidl::encoding::TypeMarker for Ipv4AddressWithPrefix {
514        type Owned = Self;
515
516        #[inline(always)]
517        fn inline_align(_context: fidl::encoding::Context) -> usize {
518            1
519        }
520
521        #[inline(always)]
522        fn inline_size(_context: fidl::encoding::Context) -> usize {
523            5
524        }
525        #[inline(always)]
526        fn encode_is_copy() -> bool {
527            true
528        }
529
530        #[inline(always)]
531        fn decode_is_copy() -> bool {
532            true
533        }
534    }
535
536    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Ipv4AddressWithPrefix, D>
537        for &Ipv4AddressWithPrefix
538    {
539        #[inline]
540        unsafe fn encode(
541            self,
542            encoder: &mut fidl::encoding::Encoder<'_, D>,
543            offset: usize,
544            _depth: fidl::encoding::Depth,
545        ) -> fidl::Result<()> {
546            encoder.debug_check_bounds::<Ipv4AddressWithPrefix>(offset);
547            unsafe {
548                // Copy the object into the buffer.
549                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
550                (buf_ptr as *mut Ipv4AddressWithPrefix)
551                    .write_unaligned((self as *const Ipv4AddressWithPrefix).read());
552                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
553                // done second because the memcpy will write garbage to these bytes.
554            }
555            Ok(())
556        }
557    }
558    unsafe impl<
559        D: fidl::encoding::ResourceDialect,
560        T0: fidl::encoding::Encode<Ipv4Address, D>,
561        T1: fidl::encoding::Encode<u8, D>,
562    > fidl::encoding::Encode<Ipv4AddressWithPrefix, D> for (T0, T1)
563    {
564        #[inline]
565        unsafe fn encode(
566            self,
567            encoder: &mut fidl::encoding::Encoder<'_, D>,
568            offset: usize,
569            depth: fidl::encoding::Depth,
570        ) -> fidl::Result<()> {
571            encoder.debug_check_bounds::<Ipv4AddressWithPrefix>(offset);
572            // Zero out padding regions. There's no need to apply masks
573            // because the unmasked parts will be overwritten by fields.
574            // Write the fields.
575            self.0.encode(encoder, offset + 0, depth)?;
576            self.1.encode(encoder, offset + 4, depth)?;
577            Ok(())
578        }
579    }
580
581    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Ipv4AddressWithPrefix {
582        #[inline(always)]
583        fn new_empty() -> Self {
584            Self { addr: fidl::new_empty!(Ipv4Address, D), prefix_len: fidl::new_empty!(u8, D) }
585        }
586
587        #[inline]
588        unsafe fn decode(
589            &mut self,
590            decoder: &mut fidl::encoding::Decoder<'_, D>,
591            offset: usize,
592            _depth: fidl::encoding::Depth,
593        ) -> fidl::Result<()> {
594            decoder.debug_check_bounds::<Self>(offset);
595            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
596            // Verify that padding bytes are zero.
597            // Copy from the buffer into the object.
598            unsafe {
599                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 5);
600            }
601            Ok(())
602        }
603    }
604
605    impl fidl::encoding::ValueTypeMarker for Ipv4SocketAddress {
606        type Borrowed<'a> = &'a Self;
607        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
608            value
609        }
610    }
611
612    unsafe impl fidl::encoding::TypeMarker for Ipv4SocketAddress {
613        type Owned = Self;
614
615        #[inline(always)]
616        fn inline_align(_context: fidl::encoding::Context) -> usize {
617            2
618        }
619
620        #[inline(always)]
621        fn inline_size(_context: fidl::encoding::Context) -> usize {
622            6
623        }
624        #[inline(always)]
625        fn encode_is_copy() -> bool {
626            true
627        }
628
629        #[inline(always)]
630        fn decode_is_copy() -> bool {
631            true
632        }
633    }
634
635    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Ipv4SocketAddress, D>
636        for &Ipv4SocketAddress
637    {
638        #[inline]
639        unsafe fn encode(
640            self,
641            encoder: &mut fidl::encoding::Encoder<'_, D>,
642            offset: usize,
643            _depth: fidl::encoding::Depth,
644        ) -> fidl::Result<()> {
645            encoder.debug_check_bounds::<Ipv4SocketAddress>(offset);
646            unsafe {
647                // Copy the object into the buffer.
648                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
649                (buf_ptr as *mut Ipv4SocketAddress)
650                    .write_unaligned((self as *const Ipv4SocketAddress).read());
651                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
652                // done second because the memcpy will write garbage to these bytes.
653            }
654            Ok(())
655        }
656    }
657    unsafe impl<
658        D: fidl::encoding::ResourceDialect,
659        T0: fidl::encoding::Encode<Ipv4Address, D>,
660        T1: fidl::encoding::Encode<u16, D>,
661    > fidl::encoding::Encode<Ipv4SocketAddress, D> for (T0, T1)
662    {
663        #[inline]
664        unsafe fn encode(
665            self,
666            encoder: &mut fidl::encoding::Encoder<'_, D>,
667            offset: usize,
668            depth: fidl::encoding::Depth,
669        ) -> fidl::Result<()> {
670            encoder.debug_check_bounds::<Ipv4SocketAddress>(offset);
671            // Zero out padding regions. There's no need to apply masks
672            // because the unmasked parts will be overwritten by fields.
673            // Write the fields.
674            self.0.encode(encoder, offset + 0, depth)?;
675            self.1.encode(encoder, offset + 4, depth)?;
676            Ok(())
677        }
678    }
679
680    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Ipv4SocketAddress {
681        #[inline(always)]
682        fn new_empty() -> Self {
683            Self { address: fidl::new_empty!(Ipv4Address, D), port: fidl::new_empty!(u16, D) }
684        }
685
686        #[inline]
687        unsafe fn decode(
688            &mut self,
689            decoder: &mut fidl::encoding::Decoder<'_, D>,
690            offset: usize,
691            _depth: fidl::encoding::Depth,
692        ) -> fidl::Result<()> {
693            decoder.debug_check_bounds::<Self>(offset);
694            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
695            // Verify that padding bytes are zero.
696            // Copy from the buffer into the object.
697            unsafe {
698                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 6);
699            }
700            Ok(())
701        }
702    }
703
704    impl fidl::encoding::ValueTypeMarker for Ipv6Address {
705        type Borrowed<'a> = &'a Self;
706        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
707            value
708        }
709    }
710
711    unsafe impl fidl::encoding::TypeMarker for Ipv6Address {
712        type Owned = Self;
713
714        #[inline(always)]
715        fn inline_align(_context: fidl::encoding::Context) -> usize {
716            1
717        }
718
719        #[inline(always)]
720        fn inline_size(_context: fidl::encoding::Context) -> usize {
721            16
722        }
723        #[inline(always)]
724        fn encode_is_copy() -> bool {
725            true
726        }
727
728        #[inline(always)]
729        fn decode_is_copy() -> bool {
730            true
731        }
732    }
733
734    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Ipv6Address, D>
735        for &Ipv6Address
736    {
737        #[inline]
738        unsafe fn encode(
739            self,
740            encoder: &mut fidl::encoding::Encoder<'_, D>,
741            offset: usize,
742            _depth: fidl::encoding::Depth,
743        ) -> fidl::Result<()> {
744            encoder.debug_check_bounds::<Ipv6Address>(offset);
745            unsafe {
746                // Copy the object into the buffer.
747                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
748                (buf_ptr as *mut Ipv6Address).write_unaligned((self as *const Ipv6Address).read());
749                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
750                // done second because the memcpy will write garbage to these bytes.
751            }
752            Ok(())
753        }
754    }
755    unsafe impl<
756        D: fidl::encoding::ResourceDialect,
757        T0: fidl::encoding::Encode<fidl::encoding::Array<u8, 16>, D>,
758    > fidl::encoding::Encode<Ipv6Address, D> for (T0,)
759    {
760        #[inline]
761        unsafe fn encode(
762            self,
763            encoder: &mut fidl::encoding::Encoder<'_, D>,
764            offset: usize,
765            depth: fidl::encoding::Depth,
766        ) -> fidl::Result<()> {
767            encoder.debug_check_bounds::<Ipv6Address>(offset);
768            // Zero out padding regions. There's no need to apply masks
769            // because the unmasked parts will be overwritten by fields.
770            // Write the fields.
771            self.0.encode(encoder, offset + 0, depth)?;
772            Ok(())
773        }
774    }
775
776    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Ipv6Address {
777        #[inline(always)]
778        fn new_empty() -> Self {
779            Self { addr: fidl::new_empty!(fidl::encoding::Array<u8, 16>, D) }
780        }
781
782        #[inline]
783        unsafe fn decode(
784            &mut self,
785            decoder: &mut fidl::encoding::Decoder<'_, D>,
786            offset: usize,
787            _depth: fidl::encoding::Depth,
788        ) -> fidl::Result<()> {
789            decoder.debug_check_bounds::<Self>(offset);
790            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
791            // Verify that padding bytes are zero.
792            // Copy from the buffer into the object.
793            unsafe {
794                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 16);
795            }
796            Ok(())
797        }
798    }
799
800    impl fidl::encoding::ValueTypeMarker for Ipv6AddressWithPrefix {
801        type Borrowed<'a> = &'a Self;
802        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
803            value
804        }
805    }
806
807    unsafe impl fidl::encoding::TypeMarker for Ipv6AddressWithPrefix {
808        type Owned = Self;
809
810        #[inline(always)]
811        fn inline_align(_context: fidl::encoding::Context) -> usize {
812            1
813        }
814
815        #[inline(always)]
816        fn inline_size(_context: fidl::encoding::Context) -> usize {
817            17
818        }
819        #[inline(always)]
820        fn encode_is_copy() -> bool {
821            true
822        }
823
824        #[inline(always)]
825        fn decode_is_copy() -> bool {
826            true
827        }
828    }
829
830    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Ipv6AddressWithPrefix, D>
831        for &Ipv6AddressWithPrefix
832    {
833        #[inline]
834        unsafe fn encode(
835            self,
836            encoder: &mut fidl::encoding::Encoder<'_, D>,
837            offset: usize,
838            _depth: fidl::encoding::Depth,
839        ) -> fidl::Result<()> {
840            encoder.debug_check_bounds::<Ipv6AddressWithPrefix>(offset);
841            unsafe {
842                // Copy the object into the buffer.
843                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
844                (buf_ptr as *mut Ipv6AddressWithPrefix)
845                    .write_unaligned((self as *const Ipv6AddressWithPrefix).read());
846                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
847                // done second because the memcpy will write garbage to these bytes.
848            }
849            Ok(())
850        }
851    }
852    unsafe impl<
853        D: fidl::encoding::ResourceDialect,
854        T0: fidl::encoding::Encode<Ipv6Address, D>,
855        T1: fidl::encoding::Encode<u8, D>,
856    > fidl::encoding::Encode<Ipv6AddressWithPrefix, D> for (T0, T1)
857    {
858        #[inline]
859        unsafe fn encode(
860            self,
861            encoder: &mut fidl::encoding::Encoder<'_, D>,
862            offset: usize,
863            depth: fidl::encoding::Depth,
864        ) -> fidl::Result<()> {
865            encoder.debug_check_bounds::<Ipv6AddressWithPrefix>(offset);
866            // Zero out padding regions. There's no need to apply masks
867            // because the unmasked parts will be overwritten by fields.
868            // Write the fields.
869            self.0.encode(encoder, offset + 0, depth)?;
870            self.1.encode(encoder, offset + 16, depth)?;
871            Ok(())
872        }
873    }
874
875    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Ipv6AddressWithPrefix {
876        #[inline(always)]
877        fn new_empty() -> Self {
878            Self { addr: fidl::new_empty!(Ipv6Address, D), prefix_len: fidl::new_empty!(u8, D) }
879        }
880
881        #[inline]
882        unsafe fn decode(
883            &mut self,
884            decoder: &mut fidl::encoding::Decoder<'_, D>,
885            offset: usize,
886            _depth: fidl::encoding::Depth,
887        ) -> fidl::Result<()> {
888            decoder.debug_check_bounds::<Self>(offset);
889            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
890            // Verify that padding bytes are zero.
891            // Copy from the buffer into the object.
892            unsafe {
893                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 17);
894            }
895            Ok(())
896        }
897    }
898
899    impl fidl::encoding::ValueTypeMarker for Ipv6SocketAddress {
900        type Borrowed<'a> = &'a Self;
901        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
902            value
903        }
904    }
905
906    unsafe impl fidl::encoding::TypeMarker for Ipv6SocketAddress {
907        type Owned = Self;
908
909        #[inline(always)]
910        fn inline_align(_context: fidl::encoding::Context) -> usize {
911            8
912        }
913
914        #[inline(always)]
915        fn inline_size(_context: fidl::encoding::Context) -> usize {
916            32
917        }
918    }
919
920    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Ipv6SocketAddress, D>
921        for &Ipv6SocketAddress
922    {
923        #[inline]
924        unsafe fn encode(
925            self,
926            encoder: &mut fidl::encoding::Encoder<'_, D>,
927            offset: usize,
928            _depth: fidl::encoding::Depth,
929        ) -> fidl::Result<()> {
930            encoder.debug_check_bounds::<Ipv6SocketAddress>(offset);
931            unsafe {
932                // Copy the object into the buffer.
933                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
934                (buf_ptr as *mut Ipv6SocketAddress)
935                    .write_unaligned((self as *const Ipv6SocketAddress).read());
936                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
937                // done second because the memcpy will write garbage to these bytes.
938                let padding_ptr = buf_ptr.offset(16) as *mut u64;
939                let padding_mask = 0xffffffffffff0000u64;
940                padding_ptr.write_unaligned(padding_ptr.read_unaligned() & !padding_mask);
941            }
942            Ok(())
943        }
944    }
945    unsafe impl<
946        D: fidl::encoding::ResourceDialect,
947        T0: fidl::encoding::Encode<Ipv6Address, D>,
948        T1: fidl::encoding::Encode<u16, D>,
949        T2: fidl::encoding::Encode<u64, D>,
950    > fidl::encoding::Encode<Ipv6SocketAddress, D> for (T0, T1, T2)
951    {
952        #[inline]
953        unsafe fn encode(
954            self,
955            encoder: &mut fidl::encoding::Encoder<'_, D>,
956            offset: usize,
957            depth: fidl::encoding::Depth,
958        ) -> fidl::Result<()> {
959            encoder.debug_check_bounds::<Ipv6SocketAddress>(offset);
960            // Zero out padding regions. There's no need to apply masks
961            // because the unmasked parts will be overwritten by fields.
962            unsafe {
963                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
964                (ptr as *mut u64).write_unaligned(0);
965            }
966            // Write the fields.
967            self.0.encode(encoder, offset + 0, depth)?;
968            self.1.encode(encoder, offset + 16, depth)?;
969            self.2.encode(encoder, offset + 24, depth)?;
970            Ok(())
971        }
972    }
973
974    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Ipv6SocketAddress {
975        #[inline(always)]
976        fn new_empty() -> Self {
977            Self {
978                address: fidl::new_empty!(Ipv6Address, D),
979                port: fidl::new_empty!(u16, D),
980                zone_index: fidl::new_empty!(u64, D),
981            }
982        }
983
984        #[inline]
985        unsafe fn decode(
986            &mut self,
987            decoder: &mut fidl::encoding::Decoder<'_, D>,
988            offset: usize,
989            _depth: fidl::encoding::Depth,
990        ) -> fidl::Result<()> {
991            decoder.debug_check_bounds::<Self>(offset);
992            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
993            // Verify that padding bytes are zero.
994            let ptr = unsafe { buf_ptr.offset(16) };
995            let padval = unsafe { (ptr as *const u64).read_unaligned() };
996            let mask = 0xffffffffffff0000u64;
997            let maskedval = padval & mask;
998            if maskedval != 0 {
999                return Err(fidl::Error::NonZeroPadding {
1000                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1001                });
1002            }
1003            // Copy from the buffer into the object.
1004            unsafe {
1005                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 32);
1006            }
1007            Ok(())
1008        }
1009    }
1010
1011    impl fidl::encoding::ValueTypeMarker for MacAddress {
1012        type Borrowed<'a> = &'a Self;
1013        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1014            value
1015        }
1016    }
1017
1018    unsafe impl fidl::encoding::TypeMarker for MacAddress {
1019        type Owned = Self;
1020
1021        #[inline(always)]
1022        fn inline_align(_context: fidl::encoding::Context) -> usize {
1023            1
1024        }
1025
1026        #[inline(always)]
1027        fn inline_size(_context: fidl::encoding::Context) -> usize {
1028            6
1029        }
1030        #[inline(always)]
1031        fn encode_is_copy() -> bool {
1032            true
1033        }
1034
1035        #[inline(always)]
1036        fn decode_is_copy() -> bool {
1037            true
1038        }
1039    }
1040
1041    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<MacAddress, D>
1042        for &MacAddress
1043    {
1044        #[inline]
1045        unsafe fn encode(
1046            self,
1047            encoder: &mut fidl::encoding::Encoder<'_, D>,
1048            offset: usize,
1049            _depth: fidl::encoding::Depth,
1050        ) -> fidl::Result<()> {
1051            encoder.debug_check_bounds::<MacAddress>(offset);
1052            unsafe {
1053                // Copy the object into the buffer.
1054                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
1055                (buf_ptr as *mut MacAddress).write_unaligned((self as *const MacAddress).read());
1056                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
1057                // done second because the memcpy will write garbage to these bytes.
1058            }
1059            Ok(())
1060        }
1061    }
1062    unsafe impl<
1063        D: fidl::encoding::ResourceDialect,
1064        T0: fidl::encoding::Encode<fidl::encoding::Array<u8, 6>, D>,
1065    > fidl::encoding::Encode<MacAddress, D> for (T0,)
1066    {
1067        #[inline]
1068        unsafe fn encode(
1069            self,
1070            encoder: &mut fidl::encoding::Encoder<'_, D>,
1071            offset: usize,
1072            depth: fidl::encoding::Depth,
1073        ) -> fidl::Result<()> {
1074            encoder.debug_check_bounds::<MacAddress>(offset);
1075            // Zero out padding regions. There's no need to apply masks
1076            // because the unmasked parts will be overwritten by fields.
1077            // Write the fields.
1078            self.0.encode(encoder, offset + 0, depth)?;
1079            Ok(())
1080        }
1081    }
1082
1083    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MacAddress {
1084        #[inline(always)]
1085        fn new_empty() -> Self {
1086            Self { octets: fidl::new_empty!(fidl::encoding::Array<u8, 6>, D) }
1087        }
1088
1089        #[inline]
1090        unsafe fn decode(
1091            &mut self,
1092            decoder: &mut fidl::encoding::Decoder<'_, D>,
1093            offset: usize,
1094            _depth: fidl::encoding::Depth,
1095        ) -> fidl::Result<()> {
1096            decoder.debug_check_bounds::<Self>(offset);
1097            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
1098            // Verify that padding bytes are zero.
1099            // Copy from the buffer into the object.
1100            unsafe {
1101                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 6);
1102            }
1103            Ok(())
1104        }
1105    }
1106
1107    impl fidl::encoding::ValueTypeMarker for Subnet {
1108        type Borrowed<'a> = &'a Self;
1109        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1110            value
1111        }
1112    }
1113
1114    unsafe impl fidl::encoding::TypeMarker for Subnet {
1115        type Owned = Self;
1116
1117        #[inline(always)]
1118        fn inline_align(_context: fidl::encoding::Context) -> usize {
1119            8
1120        }
1121
1122        #[inline(always)]
1123        fn inline_size(_context: fidl::encoding::Context) -> usize {
1124            24
1125        }
1126    }
1127
1128    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Subnet, D> for &Subnet {
1129        #[inline]
1130        unsafe fn encode(
1131            self,
1132            encoder: &mut fidl::encoding::Encoder<'_, D>,
1133            offset: usize,
1134            _depth: fidl::encoding::Depth,
1135        ) -> fidl::Result<()> {
1136            encoder.debug_check_bounds::<Subnet>(offset);
1137            // Delegate to tuple encoding.
1138            fidl::encoding::Encode::<Subnet, D>::encode(
1139                (
1140                    <IpAddress as fidl::encoding::ValueTypeMarker>::borrow(&self.addr),
1141                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.prefix_len),
1142                ),
1143                encoder,
1144                offset,
1145                _depth,
1146            )
1147        }
1148    }
1149    unsafe impl<
1150        D: fidl::encoding::ResourceDialect,
1151        T0: fidl::encoding::Encode<IpAddress, D>,
1152        T1: fidl::encoding::Encode<u8, D>,
1153    > fidl::encoding::Encode<Subnet, D> for (T0, T1)
1154    {
1155        #[inline]
1156        unsafe fn encode(
1157            self,
1158            encoder: &mut fidl::encoding::Encoder<'_, D>,
1159            offset: usize,
1160            depth: fidl::encoding::Depth,
1161        ) -> fidl::Result<()> {
1162            encoder.debug_check_bounds::<Subnet>(offset);
1163            // Zero out padding regions. There's no need to apply masks
1164            // because the unmasked parts will be overwritten by fields.
1165            unsafe {
1166                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1167                (ptr as *mut u64).write_unaligned(0);
1168            }
1169            // Write the fields.
1170            self.0.encode(encoder, offset + 0, depth)?;
1171            self.1.encode(encoder, offset + 16, depth)?;
1172            Ok(())
1173        }
1174    }
1175
1176    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Subnet {
1177        #[inline(always)]
1178        fn new_empty() -> Self {
1179            Self { addr: fidl::new_empty!(IpAddress, D), prefix_len: fidl::new_empty!(u8, D) }
1180        }
1181
1182        #[inline]
1183        unsafe fn decode(
1184            &mut self,
1185            decoder: &mut fidl::encoding::Decoder<'_, D>,
1186            offset: usize,
1187            _depth: fidl::encoding::Depth,
1188        ) -> fidl::Result<()> {
1189            decoder.debug_check_bounds::<Self>(offset);
1190            // Verify that padding bytes are zero.
1191            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1192            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1193            let mask = 0xffffffffffffff00u64;
1194            let maskedval = padval & mask;
1195            if maskedval != 0 {
1196                return Err(fidl::Error::NonZeroPadding {
1197                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1198                });
1199            }
1200            fidl::decode!(IpAddress, D, &mut self.addr, decoder, offset + 0, _depth)?;
1201            fidl::decode!(u8, D, &mut self.prefix_len, decoder, offset + 16, _depth)?;
1202            Ok(())
1203        }
1204    }
1205
1206    impl Marks {
1207        #[inline(always)]
1208        fn max_ordinal_present(&self) -> u64 {
1209            if let Some(_) = self.mark_2 {
1210                return 2;
1211            }
1212            if let Some(_) = self.mark_1 {
1213                return 1;
1214            }
1215            0
1216        }
1217    }
1218
1219    impl fidl::encoding::ValueTypeMarker for Marks {
1220        type Borrowed<'a> = &'a Self;
1221        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1222            value
1223        }
1224    }
1225
1226    unsafe impl fidl::encoding::TypeMarker for Marks {
1227        type Owned = Self;
1228
1229        #[inline(always)]
1230        fn inline_align(_context: fidl::encoding::Context) -> usize {
1231            8
1232        }
1233
1234        #[inline(always)]
1235        fn inline_size(_context: fidl::encoding::Context) -> usize {
1236            16
1237        }
1238    }
1239
1240    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Marks, D> for &Marks {
1241        unsafe fn encode(
1242            self,
1243            encoder: &mut fidl::encoding::Encoder<'_, D>,
1244            offset: usize,
1245            mut depth: fidl::encoding::Depth,
1246        ) -> fidl::Result<()> {
1247            encoder.debug_check_bounds::<Marks>(offset);
1248            // Vector header
1249            let max_ordinal: u64 = self.max_ordinal_present();
1250            encoder.write_num(max_ordinal, offset);
1251            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1252            // Calling encoder.out_of_line_offset(0) is not allowed.
1253            if max_ordinal == 0 {
1254                return Ok(());
1255            }
1256            depth.increment()?;
1257            let envelope_size = 8;
1258            let bytes_len = max_ordinal as usize * envelope_size;
1259            #[allow(unused_variables)]
1260            let offset = encoder.out_of_line_offset(bytes_len);
1261            let mut _prev_end_offset: usize = 0;
1262            if 1 > max_ordinal {
1263                return Ok(());
1264            }
1265
1266            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1267            // are envelope_size bytes.
1268            let cur_offset: usize = (1 - 1) * envelope_size;
1269
1270            // Zero reserved fields.
1271            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1272
1273            // Safety:
1274            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1275            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1276            //   envelope_size bytes, there is always sufficient room.
1277            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1278                self.mark_1.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1279                encoder,
1280                offset + cur_offset,
1281                depth,
1282            )?;
1283
1284            _prev_end_offset = cur_offset + envelope_size;
1285            if 2 > max_ordinal {
1286                return Ok(());
1287            }
1288
1289            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1290            // are envelope_size bytes.
1291            let cur_offset: usize = (2 - 1) * envelope_size;
1292
1293            // Zero reserved fields.
1294            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1295
1296            // Safety:
1297            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1298            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1299            //   envelope_size bytes, there is always sufficient room.
1300            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1301                self.mark_2.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1302                encoder,
1303                offset + cur_offset,
1304                depth,
1305            )?;
1306
1307            _prev_end_offset = cur_offset + envelope_size;
1308
1309            Ok(())
1310        }
1311    }
1312
1313    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Marks {
1314        #[inline(always)]
1315        fn new_empty() -> Self {
1316            Self::default()
1317        }
1318
1319        unsafe fn decode(
1320            &mut self,
1321            decoder: &mut fidl::encoding::Decoder<'_, D>,
1322            offset: usize,
1323            mut depth: fidl::encoding::Depth,
1324        ) -> fidl::Result<()> {
1325            decoder.debug_check_bounds::<Self>(offset);
1326            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1327                None => return Err(fidl::Error::NotNullable),
1328                Some(len) => len,
1329            };
1330            // Calling decoder.out_of_line_offset(0) is not allowed.
1331            if len == 0 {
1332                return Ok(());
1333            };
1334            depth.increment()?;
1335            let envelope_size = 8;
1336            let bytes_len = len * envelope_size;
1337            let offset = decoder.out_of_line_offset(bytes_len)?;
1338            // Decode the envelope for each type.
1339            let mut _next_ordinal_to_read = 0;
1340            let mut next_offset = offset;
1341            let end_offset = offset + bytes_len;
1342            _next_ordinal_to_read += 1;
1343            if next_offset >= end_offset {
1344                return Ok(());
1345            }
1346
1347            // Decode unknown envelopes for gaps in ordinals.
1348            while _next_ordinal_to_read < 1 {
1349                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1350                _next_ordinal_to_read += 1;
1351                next_offset += envelope_size;
1352            }
1353
1354            let next_out_of_line = decoder.next_out_of_line();
1355            let handles_before = decoder.remaining_handles();
1356            if let Some((inlined, num_bytes, num_handles)) =
1357                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1358            {
1359                let member_inline_size =
1360                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1361                if inlined != (member_inline_size <= 4) {
1362                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1363                }
1364                let inner_offset;
1365                let mut inner_depth = depth.clone();
1366                if inlined {
1367                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1368                    inner_offset = next_offset;
1369                } else {
1370                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1371                    inner_depth.increment()?;
1372                }
1373                let val_ref = self.mark_1.get_or_insert_with(|| fidl::new_empty!(u32, D));
1374                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1375                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1376                {
1377                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1378                }
1379                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1380                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1381                }
1382            }
1383
1384            next_offset += envelope_size;
1385            _next_ordinal_to_read += 1;
1386            if next_offset >= end_offset {
1387                return Ok(());
1388            }
1389
1390            // Decode unknown envelopes for gaps in ordinals.
1391            while _next_ordinal_to_read < 2 {
1392                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1393                _next_ordinal_to_read += 1;
1394                next_offset += envelope_size;
1395            }
1396
1397            let next_out_of_line = decoder.next_out_of_line();
1398            let handles_before = decoder.remaining_handles();
1399            if let Some((inlined, num_bytes, num_handles)) =
1400                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1401            {
1402                let member_inline_size =
1403                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1404                if inlined != (member_inline_size <= 4) {
1405                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1406                }
1407                let inner_offset;
1408                let mut inner_depth = depth.clone();
1409                if inlined {
1410                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1411                    inner_offset = next_offset;
1412                } else {
1413                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1414                    inner_depth.increment()?;
1415                }
1416                let val_ref = self.mark_2.get_or_insert_with(|| fidl::new_empty!(u32, D));
1417                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1418                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1419                {
1420                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1421                }
1422                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1423                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1424                }
1425            }
1426
1427            next_offset += envelope_size;
1428
1429            // Decode the remaining unknown envelopes.
1430            while next_offset < end_offset {
1431                _next_ordinal_to_read += 1;
1432                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1433                next_offset += envelope_size;
1434            }
1435
1436            Ok(())
1437        }
1438    }
1439
1440    impl fidl::encoding::ValueTypeMarker for IpAddress {
1441        type Borrowed<'a> = &'a Self;
1442        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1443            value
1444        }
1445    }
1446
1447    unsafe impl fidl::encoding::TypeMarker for IpAddress {
1448        type Owned = Self;
1449
1450        #[inline(always)]
1451        fn inline_align(_context: fidl::encoding::Context) -> usize {
1452            8
1453        }
1454
1455        #[inline(always)]
1456        fn inline_size(_context: fidl::encoding::Context) -> usize {
1457            16
1458        }
1459    }
1460
1461    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<IpAddress, D>
1462        for &IpAddress
1463    {
1464        #[inline]
1465        unsafe fn encode(
1466            self,
1467            encoder: &mut fidl::encoding::Encoder<'_, D>,
1468            offset: usize,
1469            _depth: fidl::encoding::Depth,
1470        ) -> fidl::Result<()> {
1471            encoder.debug_check_bounds::<IpAddress>(offset);
1472            encoder.write_num::<u64>(self.ordinal(), offset);
1473            match self {
1474                IpAddress::Ipv4(ref val) => fidl::encoding::encode_in_envelope::<Ipv4Address, D>(
1475                    <Ipv4Address as fidl::encoding::ValueTypeMarker>::borrow(val),
1476                    encoder,
1477                    offset + 8,
1478                    _depth,
1479                ),
1480                IpAddress::Ipv6(ref val) => fidl::encoding::encode_in_envelope::<Ipv6Address, D>(
1481                    <Ipv6Address as fidl::encoding::ValueTypeMarker>::borrow(val),
1482                    encoder,
1483                    offset + 8,
1484                    _depth,
1485                ),
1486            }
1487        }
1488    }
1489
1490    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for IpAddress {
1491        #[inline(always)]
1492        fn new_empty() -> Self {
1493            Self::Ipv4(fidl::new_empty!(Ipv4Address, D))
1494        }
1495
1496        #[inline]
1497        unsafe fn decode(
1498            &mut self,
1499            decoder: &mut fidl::encoding::Decoder<'_, D>,
1500            offset: usize,
1501            mut depth: fidl::encoding::Depth,
1502        ) -> fidl::Result<()> {
1503            decoder.debug_check_bounds::<Self>(offset);
1504            #[allow(unused_variables)]
1505            let next_out_of_line = decoder.next_out_of_line();
1506            let handles_before = decoder.remaining_handles();
1507            let (ordinal, inlined, num_bytes, num_handles) =
1508                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1509
1510            let member_inline_size = match ordinal {
1511                1 => <Ipv4Address as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1512                2 => <Ipv6Address as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1513                _ => return Err(fidl::Error::UnknownUnionTag),
1514            };
1515
1516            if inlined != (member_inline_size <= 4) {
1517                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1518            }
1519            let _inner_offset;
1520            if inlined {
1521                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1522                _inner_offset = offset + 8;
1523            } else {
1524                depth.increment()?;
1525                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1526            }
1527            match ordinal {
1528                1 => {
1529                    #[allow(irrefutable_let_patterns)]
1530                    if let IpAddress::Ipv4(_) = self {
1531                        // Do nothing, read the value into the object
1532                    } else {
1533                        // Initialize `self` to the right variant
1534                        *self = IpAddress::Ipv4(fidl::new_empty!(Ipv4Address, D));
1535                    }
1536                    #[allow(irrefutable_let_patterns)]
1537                    if let IpAddress::Ipv4(ref mut val) = self {
1538                        fidl::decode!(Ipv4Address, D, val, decoder, _inner_offset, depth)?;
1539                    } else {
1540                        unreachable!()
1541                    }
1542                }
1543                2 => {
1544                    #[allow(irrefutable_let_patterns)]
1545                    if let IpAddress::Ipv6(_) = self {
1546                        // Do nothing, read the value into the object
1547                    } else {
1548                        // Initialize `self` to the right variant
1549                        *self = IpAddress::Ipv6(fidl::new_empty!(Ipv6Address, D));
1550                    }
1551                    #[allow(irrefutable_let_patterns)]
1552                    if let IpAddress::Ipv6(ref mut val) = self {
1553                        fidl::decode!(Ipv6Address, D, val, decoder, _inner_offset, depth)?;
1554                    } else {
1555                        unreachable!()
1556                    }
1557                }
1558                ordinal => panic!("unexpected ordinal {:?}", ordinal),
1559            }
1560            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1561                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1562            }
1563            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1564                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1565            }
1566            Ok(())
1567        }
1568    }
1569
1570    impl fidl::encoding::ValueTypeMarker for SocketAddress {
1571        type Borrowed<'a> = &'a Self;
1572        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1573            value
1574        }
1575    }
1576
1577    unsafe impl fidl::encoding::TypeMarker for SocketAddress {
1578        type Owned = Self;
1579
1580        #[inline(always)]
1581        fn inline_align(_context: fidl::encoding::Context) -> usize {
1582            8
1583        }
1584
1585        #[inline(always)]
1586        fn inline_size(_context: fidl::encoding::Context) -> usize {
1587            16
1588        }
1589    }
1590
1591    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SocketAddress, D>
1592        for &SocketAddress
1593    {
1594        #[inline]
1595        unsafe fn encode(
1596            self,
1597            encoder: &mut fidl::encoding::Encoder<'_, D>,
1598            offset: usize,
1599            _depth: fidl::encoding::Depth,
1600        ) -> fidl::Result<()> {
1601            encoder.debug_check_bounds::<SocketAddress>(offset);
1602            encoder.write_num::<u64>(self.ordinal(), offset);
1603            match self {
1604                SocketAddress::Ipv4(ref val) => {
1605                    fidl::encoding::encode_in_envelope::<Ipv4SocketAddress, D>(
1606                        <Ipv4SocketAddress as fidl::encoding::ValueTypeMarker>::borrow(val),
1607                        encoder,
1608                        offset + 8,
1609                        _depth,
1610                    )
1611                }
1612                SocketAddress::Ipv6(ref val) => {
1613                    fidl::encoding::encode_in_envelope::<Ipv6SocketAddress, D>(
1614                        <Ipv6SocketAddress as fidl::encoding::ValueTypeMarker>::borrow(val),
1615                        encoder,
1616                        offset + 8,
1617                        _depth,
1618                    )
1619                }
1620            }
1621        }
1622    }
1623
1624    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SocketAddress {
1625        #[inline(always)]
1626        fn new_empty() -> Self {
1627            Self::Ipv4(fidl::new_empty!(Ipv4SocketAddress, D))
1628        }
1629
1630        #[inline]
1631        unsafe fn decode(
1632            &mut self,
1633            decoder: &mut fidl::encoding::Decoder<'_, D>,
1634            offset: usize,
1635            mut depth: fidl::encoding::Depth,
1636        ) -> fidl::Result<()> {
1637            decoder.debug_check_bounds::<Self>(offset);
1638            #[allow(unused_variables)]
1639            let next_out_of_line = decoder.next_out_of_line();
1640            let handles_before = decoder.remaining_handles();
1641            let (ordinal, inlined, num_bytes, num_handles) =
1642                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1643
1644            let member_inline_size = match ordinal {
1645                1 => {
1646                    <Ipv4SocketAddress as fidl::encoding::TypeMarker>::inline_size(decoder.context)
1647                }
1648                2 => {
1649                    <Ipv6SocketAddress as fidl::encoding::TypeMarker>::inline_size(decoder.context)
1650                }
1651                _ => return Err(fidl::Error::UnknownUnionTag),
1652            };
1653
1654            if inlined != (member_inline_size <= 4) {
1655                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1656            }
1657            let _inner_offset;
1658            if inlined {
1659                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1660                _inner_offset = offset + 8;
1661            } else {
1662                depth.increment()?;
1663                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1664            }
1665            match ordinal {
1666                1 => {
1667                    #[allow(irrefutable_let_patterns)]
1668                    if let SocketAddress::Ipv4(_) = self {
1669                        // Do nothing, read the value into the object
1670                    } else {
1671                        // Initialize `self` to the right variant
1672                        *self = SocketAddress::Ipv4(fidl::new_empty!(Ipv4SocketAddress, D));
1673                    }
1674                    #[allow(irrefutable_let_patterns)]
1675                    if let SocketAddress::Ipv4(ref mut val) = self {
1676                        fidl::decode!(Ipv4SocketAddress, D, val, decoder, _inner_offset, depth)?;
1677                    } else {
1678                        unreachable!()
1679                    }
1680                }
1681                2 => {
1682                    #[allow(irrefutable_let_patterns)]
1683                    if let SocketAddress::Ipv6(_) = self {
1684                        // Do nothing, read the value into the object
1685                    } else {
1686                        // Initialize `self` to the right variant
1687                        *self = SocketAddress::Ipv6(fidl::new_empty!(Ipv6SocketAddress, D));
1688                    }
1689                    #[allow(irrefutable_let_patterns)]
1690                    if let SocketAddress::Ipv6(ref mut val) = self {
1691                        fidl::decode!(Ipv6SocketAddress, D, val, decoder, _inner_offset, depth)?;
1692                    } else {
1693                        unreachable!()
1694                    }
1695                }
1696                ordinal => panic!("unexpected ordinal {:?}", ordinal),
1697            }
1698            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1699                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1700            }
1701            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1702                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1703            }
1704            Ok(())
1705        }
1706    }
1707}