fidl_fuchsia_net_ndp__common/
fidl_fuchsia_net_ndp__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/// The identifier of an NDP option type, aka the "type" field in the NDP option
12/// as described in [RFC 4861 section
13/// 4.6](https://datatracker.ietf.org/doc/html/rfc4861#section-4.6).
14pub type OptionType = u8;
15
16/// The maximum number of distinct option types that can be specified for
17/// watcher interest.
18pub const MAX_NUM_OPTION_TYPES: u16 = 256;
19
20/// The maximum number of options that can be yielded in a single watcher batch.
21pub const MAX_OPTION_BATCH_SIZE: u8 = 16;
22
23/// The maximum possible length in bytes of an NDP option body (excluding the
24/// type and length bytes).
25pub const MAX_OPTION_BODY_LENGTH: u16 = 2038;
26
27#[derive(Clone, Debug, PartialEq)]
28pub struct OptionWatcherWatchOptionsResponse {
29    /// A batch of yielded options.
30    pub options: Vec<OptionWatchEntry>,
31    /// A count of the number of options dropped since the last time
32    /// `WatchOptions` was called (or since the watcher was created if this
33    /// is the first time it was called).
34    pub dropped: u32,
35}
36
37impl fidl::Persistable for OptionWatcherWatchOptionsResponse {}
38
39/// An entry representing a single option received in an NDP message.
40///
41/// The `option_type` and `body` are not guaranteed to be validated in any way
42/// other than the `body` conforming to length requirements as specified in [RFC
43/// 4861 section
44/// 4.6](https://datatracker.ietf.org/doc/html/rfc4861#section-4.6).
45#[derive(Clone, Debug, Default, PartialEq)]
46pub struct OptionWatchEntry {
47    /// The interface on which the NDP message containing the option was
48    /// received.
49    ///
50    /// Always present.
51    pub interface_id: Option<u64>,
52    /// The source address of the IPv6 packet containing the NDP message in
53    /// which the option was received.
54    ///
55    /// Always present.
56    pub source_address: Option<fidl_fuchsia_net__common::Ipv6Address>,
57    /// The NDP option type.
58    ///
59    /// Always present.
60    pub option_type: Option<u8>,
61    /// The body of the NDP option.
62    ///
63    /// The raw bytes of the NDP option excluding the leading two bytes for the
64    /// type and the length according to [RFC 4861 section
65    /// 4.6](https://datatracker.ietf.org/doc/html/rfc4861#section-4.6). The
66    /// body is padded such that if it were prepended with a type octet and a
67    /// length octet to match the format described in RFC 4861 section 4.6, its
68    /// length would be a multiple of 8 octets (as required by the RFC).
69    ///
70    /// Always present.
71    pub body: Option<Vec<u8>>,
72    #[doc(hidden)]
73    pub __source_breaking: fidl::marker::SourceBreaking,
74}
75
76impl fidl::Persistable for OptionWatchEntry {}
77
78/// Parameters for a router advertisement option watcher.
79#[derive(Clone, Debug, Default, PartialEq)]
80pub struct RouterAdvertisementOptionWatcherParams {
81    /// The set of option types that should be yielded on the watcher.
82    ///
83    /// Indicates all option types should be yielded if absent.
84    pub interest_types: Option<Vec<u8>>,
85    /// If set, only options received via the specified interface will be
86    /// yielded.
87    ///
88    /// Indicates options received via all interfaces should be yielded if
89    /// absent.
90    pub interest_interface_id: Option<u64>,
91    #[doc(hidden)]
92    pub __source_breaking: fidl::marker::SourceBreaking,
93}
94
95impl fidl::Persistable for RouterAdvertisementOptionWatcherParams {}
96
97pub mod option_watcher_ordinals {
98    pub const PROBE: u64 = 0x11ef2cfafa567e8d;
99    pub const WATCH_OPTIONS: u64 = 0x6d7b8e3d3f84faf5;
100}
101
102pub mod router_advertisement_option_watcher_provider_ordinals {
103    pub const NEW_ROUTER_ADVERTISEMENT_OPTION_WATCHER: u64 = 0x2a90a8bd5fd2bbf4;
104}
105
106mod internal {
107    use super::*;
108
109    impl fidl::encoding::ValueTypeMarker for OptionWatcherWatchOptionsResponse {
110        type Borrowed<'a> = &'a Self;
111        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
112            value
113        }
114    }
115
116    unsafe impl fidl::encoding::TypeMarker for OptionWatcherWatchOptionsResponse {
117        type Owned = Self;
118
119        #[inline(always)]
120        fn inline_align(_context: fidl::encoding::Context) -> usize {
121            8
122        }
123
124        #[inline(always)]
125        fn inline_size(_context: fidl::encoding::Context) -> usize {
126            24
127        }
128    }
129
130    unsafe impl<D: fidl::encoding::ResourceDialect>
131        fidl::encoding::Encode<OptionWatcherWatchOptionsResponse, D>
132        for &OptionWatcherWatchOptionsResponse
133    {
134        #[inline]
135        unsafe fn encode(
136            self,
137            encoder: &mut fidl::encoding::Encoder<'_, D>,
138            offset: usize,
139            _depth: fidl::encoding::Depth,
140        ) -> fidl::Result<()> {
141            encoder.debug_check_bounds::<OptionWatcherWatchOptionsResponse>(offset);
142            // Delegate to tuple encoding.
143            fidl::encoding::Encode::<OptionWatcherWatchOptionsResponse, D>::encode(
144                (
145                    <fidl::encoding::Vector<OptionWatchEntry, 16> as fidl::encoding::ValueTypeMarker>::borrow(&self.options),
146                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.dropped),
147                ),
148                encoder, offset, _depth
149            )
150        }
151    }
152    unsafe impl<
153            D: fidl::encoding::ResourceDialect,
154            T0: fidl::encoding::Encode<fidl::encoding::Vector<OptionWatchEntry, 16>, D>,
155            T1: fidl::encoding::Encode<u32, D>,
156        > fidl::encoding::Encode<OptionWatcherWatchOptionsResponse, D> for (T0, T1)
157    {
158        #[inline]
159        unsafe fn encode(
160            self,
161            encoder: &mut fidl::encoding::Encoder<'_, D>,
162            offset: usize,
163            depth: fidl::encoding::Depth,
164        ) -> fidl::Result<()> {
165            encoder.debug_check_bounds::<OptionWatcherWatchOptionsResponse>(offset);
166            // Zero out padding regions. There's no need to apply masks
167            // because the unmasked parts will be overwritten by fields.
168            unsafe {
169                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
170                (ptr as *mut u64).write_unaligned(0);
171            }
172            // Write the fields.
173            self.0.encode(encoder, offset + 0, depth)?;
174            self.1.encode(encoder, offset + 16, depth)?;
175            Ok(())
176        }
177    }
178
179    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
180        for OptionWatcherWatchOptionsResponse
181    {
182        #[inline(always)]
183        fn new_empty() -> Self {
184            Self {
185                options: fidl::new_empty!(fidl::encoding::Vector<OptionWatchEntry, 16>, D),
186                dropped: fidl::new_empty!(u32, D),
187            }
188        }
189
190        #[inline]
191        unsafe fn decode(
192            &mut self,
193            decoder: &mut fidl::encoding::Decoder<'_, D>,
194            offset: usize,
195            _depth: fidl::encoding::Depth,
196        ) -> fidl::Result<()> {
197            decoder.debug_check_bounds::<Self>(offset);
198            // Verify that padding bytes are zero.
199            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
200            let padval = unsafe { (ptr as *const u64).read_unaligned() };
201            let mask = 0xffffffff00000000u64;
202            let maskedval = padval & mask;
203            if maskedval != 0 {
204                return Err(fidl::Error::NonZeroPadding {
205                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
206                });
207            }
208            fidl::decode!(fidl::encoding::Vector<OptionWatchEntry, 16>, D, &mut self.options, decoder, offset + 0, _depth)?;
209            fidl::decode!(u32, D, &mut self.dropped, decoder, offset + 16, _depth)?;
210            Ok(())
211        }
212    }
213
214    impl OptionWatchEntry {
215        #[inline(always)]
216        fn max_ordinal_present(&self) -> u64 {
217            if let Some(_) = self.body {
218                return 4;
219            }
220            if let Some(_) = self.option_type {
221                return 3;
222            }
223            if let Some(_) = self.source_address {
224                return 2;
225            }
226            if let Some(_) = self.interface_id {
227                return 1;
228            }
229            0
230        }
231    }
232
233    impl fidl::encoding::ValueTypeMarker for OptionWatchEntry {
234        type Borrowed<'a> = &'a Self;
235        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
236            value
237        }
238    }
239
240    unsafe impl fidl::encoding::TypeMarker for OptionWatchEntry {
241        type Owned = Self;
242
243        #[inline(always)]
244        fn inline_align(_context: fidl::encoding::Context) -> usize {
245            8
246        }
247
248        #[inline(always)]
249        fn inline_size(_context: fidl::encoding::Context) -> usize {
250            16
251        }
252    }
253
254    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<OptionWatchEntry, D>
255        for &OptionWatchEntry
256    {
257        unsafe fn encode(
258            self,
259            encoder: &mut fidl::encoding::Encoder<'_, D>,
260            offset: usize,
261            mut depth: fidl::encoding::Depth,
262        ) -> fidl::Result<()> {
263            encoder.debug_check_bounds::<OptionWatchEntry>(offset);
264            // Vector header
265            let max_ordinal: u64 = self.max_ordinal_present();
266            encoder.write_num(max_ordinal, offset);
267            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
268            // Calling encoder.out_of_line_offset(0) is not allowed.
269            if max_ordinal == 0 {
270                return Ok(());
271            }
272            depth.increment()?;
273            let envelope_size = 8;
274            let bytes_len = max_ordinal as usize * envelope_size;
275            #[allow(unused_variables)]
276            let offset = encoder.out_of_line_offset(bytes_len);
277            let mut _prev_end_offset: usize = 0;
278            if 1 > max_ordinal {
279                return Ok(());
280            }
281
282            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
283            // are envelope_size bytes.
284            let cur_offset: usize = (1 - 1) * envelope_size;
285
286            // Zero reserved fields.
287            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
288
289            // Safety:
290            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
291            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
292            //   envelope_size bytes, there is always sufficient room.
293            fidl::encoding::encode_in_envelope_optional::<u64, D>(
294                self.interface_id.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
295                encoder,
296                offset + cur_offset,
297                depth,
298            )?;
299
300            _prev_end_offset = cur_offset + envelope_size;
301            if 2 > max_ordinal {
302                return Ok(());
303            }
304
305            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
306            // are envelope_size bytes.
307            let cur_offset: usize = (2 - 1) * envelope_size;
308
309            // Zero reserved fields.
310            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
311
312            // Safety:
313            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
314            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
315            //   envelope_size bytes, there is always sufficient room.
316            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_net__common::Ipv6Address, D>(
317            self.source_address.as_ref().map(<fidl_fuchsia_net__common::Ipv6Address as fidl::encoding::ValueTypeMarker>::borrow),
318            encoder, offset + cur_offset, depth
319        )?;
320
321            _prev_end_offset = cur_offset + envelope_size;
322            if 3 > max_ordinal {
323                return Ok(());
324            }
325
326            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
327            // are envelope_size bytes.
328            let cur_offset: usize = (3 - 1) * envelope_size;
329
330            // Zero reserved fields.
331            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
332
333            // Safety:
334            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
335            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
336            //   envelope_size bytes, there is always sufficient room.
337            fidl::encoding::encode_in_envelope_optional::<u8, D>(
338                self.option_type.as_ref().map(<u8 as fidl::encoding::ValueTypeMarker>::borrow),
339                encoder,
340                offset + cur_offset,
341                depth,
342            )?;
343
344            _prev_end_offset = cur_offset + envelope_size;
345            if 4 > max_ordinal {
346                return Ok(());
347            }
348
349            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
350            // are envelope_size bytes.
351            let cur_offset: usize = (4 - 1) * envelope_size;
352
353            // Zero reserved fields.
354            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
355
356            // Safety:
357            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
358            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
359            //   envelope_size bytes, there is always sufficient room.
360            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Vector<u8, 2038>, D>(
361                self.body.as_ref().map(
362                    <fidl::encoding::Vector<u8, 2038> as fidl::encoding::ValueTypeMarker>::borrow,
363                ),
364                encoder,
365                offset + cur_offset,
366                depth,
367            )?;
368
369            _prev_end_offset = cur_offset + envelope_size;
370
371            Ok(())
372        }
373    }
374
375    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for OptionWatchEntry {
376        #[inline(always)]
377        fn new_empty() -> Self {
378            Self::default()
379        }
380
381        unsafe fn decode(
382            &mut self,
383            decoder: &mut fidl::encoding::Decoder<'_, D>,
384            offset: usize,
385            mut depth: fidl::encoding::Depth,
386        ) -> fidl::Result<()> {
387            decoder.debug_check_bounds::<Self>(offset);
388            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
389                None => return Err(fidl::Error::NotNullable),
390                Some(len) => len,
391            };
392            // Calling decoder.out_of_line_offset(0) is not allowed.
393            if len == 0 {
394                return Ok(());
395            };
396            depth.increment()?;
397            let envelope_size = 8;
398            let bytes_len = len * envelope_size;
399            let offset = decoder.out_of_line_offset(bytes_len)?;
400            // Decode the envelope for each type.
401            let mut _next_ordinal_to_read = 0;
402            let mut next_offset = offset;
403            let end_offset = offset + bytes_len;
404            _next_ordinal_to_read += 1;
405            if next_offset >= end_offset {
406                return Ok(());
407            }
408
409            // Decode unknown envelopes for gaps in ordinals.
410            while _next_ordinal_to_read < 1 {
411                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
412                _next_ordinal_to_read += 1;
413                next_offset += envelope_size;
414            }
415
416            let next_out_of_line = decoder.next_out_of_line();
417            let handles_before = decoder.remaining_handles();
418            if let Some((inlined, num_bytes, num_handles)) =
419                fidl::encoding::decode_envelope_header(decoder, next_offset)?
420            {
421                let member_inline_size =
422                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
423                if inlined != (member_inline_size <= 4) {
424                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
425                }
426                let inner_offset;
427                let mut inner_depth = depth.clone();
428                if inlined {
429                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
430                    inner_offset = next_offset;
431                } else {
432                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
433                    inner_depth.increment()?;
434                }
435                let val_ref = self.interface_id.get_or_insert_with(|| fidl::new_empty!(u64, D));
436                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
437                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
438                {
439                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
440                }
441                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
442                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
443                }
444            }
445
446            next_offset += envelope_size;
447            _next_ordinal_to_read += 1;
448            if next_offset >= end_offset {
449                return Ok(());
450            }
451
452            // Decode unknown envelopes for gaps in ordinals.
453            while _next_ordinal_to_read < 2 {
454                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
455                _next_ordinal_to_read += 1;
456                next_offset += envelope_size;
457            }
458
459            let next_out_of_line = decoder.next_out_of_line();
460            let handles_before = decoder.remaining_handles();
461            if let Some((inlined, num_bytes, num_handles)) =
462                fidl::encoding::decode_envelope_header(decoder, next_offset)?
463            {
464                let member_inline_size = <fidl_fuchsia_net__common::Ipv6Address as fidl::encoding::TypeMarker>::inline_size(decoder.context);
465                if inlined != (member_inline_size <= 4) {
466                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
467                }
468                let inner_offset;
469                let mut inner_depth = depth.clone();
470                if inlined {
471                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
472                    inner_offset = next_offset;
473                } else {
474                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
475                    inner_depth.increment()?;
476                }
477                let val_ref = self.source_address.get_or_insert_with(|| {
478                    fidl::new_empty!(fidl_fuchsia_net__common::Ipv6Address, D)
479                });
480                fidl::decode!(
481                    fidl_fuchsia_net__common::Ipv6Address,
482                    D,
483                    val_ref,
484                    decoder,
485                    inner_offset,
486                    inner_depth
487                )?;
488                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
489                {
490                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
491                }
492                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
493                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
494                }
495            }
496
497            next_offset += envelope_size;
498            _next_ordinal_to_read += 1;
499            if next_offset >= end_offset {
500                return Ok(());
501            }
502
503            // Decode unknown envelopes for gaps in ordinals.
504            while _next_ordinal_to_read < 3 {
505                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
506                _next_ordinal_to_read += 1;
507                next_offset += envelope_size;
508            }
509
510            let next_out_of_line = decoder.next_out_of_line();
511            let handles_before = decoder.remaining_handles();
512            if let Some((inlined, num_bytes, num_handles)) =
513                fidl::encoding::decode_envelope_header(decoder, next_offset)?
514            {
515                let member_inline_size =
516                    <u8 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
517                if inlined != (member_inline_size <= 4) {
518                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
519                }
520                let inner_offset;
521                let mut inner_depth = depth.clone();
522                if inlined {
523                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
524                    inner_offset = next_offset;
525                } else {
526                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
527                    inner_depth.increment()?;
528                }
529                let val_ref = self.option_type.get_or_insert_with(|| fidl::new_empty!(u8, D));
530                fidl::decode!(u8, D, val_ref, decoder, inner_offset, inner_depth)?;
531                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
532                {
533                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
534                }
535                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
536                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
537                }
538            }
539
540            next_offset += envelope_size;
541            _next_ordinal_to_read += 1;
542            if next_offset >= end_offset {
543                return Ok(());
544            }
545
546            // Decode unknown envelopes for gaps in ordinals.
547            while _next_ordinal_to_read < 4 {
548                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
549                _next_ordinal_to_read += 1;
550                next_offset += envelope_size;
551            }
552
553            let next_out_of_line = decoder.next_out_of_line();
554            let handles_before = decoder.remaining_handles();
555            if let Some((inlined, num_bytes, num_handles)) =
556                fidl::encoding::decode_envelope_header(decoder, next_offset)?
557            {
558                let member_inline_size =
559                    <fidl::encoding::Vector<u8, 2038> as fidl::encoding::TypeMarker>::inline_size(
560                        decoder.context,
561                    );
562                if inlined != (member_inline_size <= 4) {
563                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
564                }
565                let inner_offset;
566                let mut inner_depth = depth.clone();
567                if inlined {
568                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
569                    inner_offset = next_offset;
570                } else {
571                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
572                    inner_depth.increment()?;
573                }
574                let val_ref = self
575                    .body
576                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Vector<u8, 2038>, D));
577                fidl::decode!(fidl::encoding::Vector<u8, 2038>, D, val_ref, decoder, inner_offset, inner_depth)?;
578                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
579                {
580                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
581                }
582                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
583                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
584                }
585            }
586
587            next_offset += envelope_size;
588
589            // Decode the remaining unknown envelopes.
590            while next_offset < end_offset {
591                _next_ordinal_to_read += 1;
592                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
593                next_offset += envelope_size;
594            }
595
596            Ok(())
597        }
598    }
599
600    impl RouterAdvertisementOptionWatcherParams {
601        #[inline(always)]
602        fn max_ordinal_present(&self) -> u64 {
603            if let Some(_) = self.interest_interface_id {
604                return 2;
605            }
606            if let Some(_) = self.interest_types {
607                return 1;
608            }
609            0
610        }
611    }
612
613    impl fidl::encoding::ValueTypeMarker for RouterAdvertisementOptionWatcherParams {
614        type Borrowed<'a> = &'a Self;
615        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
616            value
617        }
618    }
619
620    unsafe impl fidl::encoding::TypeMarker for RouterAdvertisementOptionWatcherParams {
621        type Owned = Self;
622
623        #[inline(always)]
624        fn inline_align(_context: fidl::encoding::Context) -> usize {
625            8
626        }
627
628        #[inline(always)]
629        fn inline_size(_context: fidl::encoding::Context) -> usize {
630            16
631        }
632    }
633
634    unsafe impl<D: fidl::encoding::ResourceDialect>
635        fidl::encoding::Encode<RouterAdvertisementOptionWatcherParams, D>
636        for &RouterAdvertisementOptionWatcherParams
637    {
638        unsafe fn encode(
639            self,
640            encoder: &mut fidl::encoding::Encoder<'_, D>,
641            offset: usize,
642            mut depth: fidl::encoding::Depth,
643        ) -> fidl::Result<()> {
644            encoder.debug_check_bounds::<RouterAdvertisementOptionWatcherParams>(offset);
645            // Vector header
646            let max_ordinal: u64 = self.max_ordinal_present();
647            encoder.write_num(max_ordinal, offset);
648            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
649            // Calling encoder.out_of_line_offset(0) is not allowed.
650            if max_ordinal == 0 {
651                return Ok(());
652            }
653            depth.increment()?;
654            let envelope_size = 8;
655            let bytes_len = max_ordinal as usize * envelope_size;
656            #[allow(unused_variables)]
657            let offset = encoder.out_of_line_offset(bytes_len);
658            let mut _prev_end_offset: usize = 0;
659            if 1 > max_ordinal {
660                return Ok(());
661            }
662
663            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
664            // are envelope_size bytes.
665            let cur_offset: usize = (1 - 1) * envelope_size;
666
667            // Zero reserved fields.
668            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
669
670            // Safety:
671            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
672            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
673            //   envelope_size bytes, there is always sufficient room.
674            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Vector<u8, 256>, D>(
675                self.interest_types.as_ref().map(
676                    <fidl::encoding::Vector<u8, 256> as fidl::encoding::ValueTypeMarker>::borrow,
677                ),
678                encoder,
679                offset + cur_offset,
680                depth,
681            )?;
682
683            _prev_end_offset = cur_offset + envelope_size;
684            if 2 > max_ordinal {
685                return Ok(());
686            }
687
688            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
689            // are envelope_size bytes.
690            let cur_offset: usize = (2 - 1) * envelope_size;
691
692            // Zero reserved fields.
693            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
694
695            // Safety:
696            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
697            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
698            //   envelope_size bytes, there is always sufficient room.
699            fidl::encoding::encode_in_envelope_optional::<u64, D>(
700                self.interest_interface_id
701                    .as_ref()
702                    .map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
703                encoder,
704                offset + cur_offset,
705                depth,
706            )?;
707
708            _prev_end_offset = cur_offset + envelope_size;
709
710            Ok(())
711        }
712    }
713
714    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
715        for RouterAdvertisementOptionWatcherParams
716    {
717        #[inline(always)]
718        fn new_empty() -> Self {
719            Self::default()
720        }
721
722        unsafe fn decode(
723            &mut self,
724            decoder: &mut fidl::encoding::Decoder<'_, D>,
725            offset: usize,
726            mut depth: fidl::encoding::Depth,
727        ) -> fidl::Result<()> {
728            decoder.debug_check_bounds::<Self>(offset);
729            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
730                None => return Err(fidl::Error::NotNullable),
731                Some(len) => len,
732            };
733            // Calling decoder.out_of_line_offset(0) is not allowed.
734            if len == 0 {
735                return Ok(());
736            };
737            depth.increment()?;
738            let envelope_size = 8;
739            let bytes_len = len * envelope_size;
740            let offset = decoder.out_of_line_offset(bytes_len)?;
741            // Decode the envelope for each type.
742            let mut _next_ordinal_to_read = 0;
743            let mut next_offset = offset;
744            let end_offset = offset + bytes_len;
745            _next_ordinal_to_read += 1;
746            if next_offset >= end_offset {
747                return Ok(());
748            }
749
750            // Decode unknown envelopes for gaps in ordinals.
751            while _next_ordinal_to_read < 1 {
752                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
753                _next_ordinal_to_read += 1;
754                next_offset += envelope_size;
755            }
756
757            let next_out_of_line = decoder.next_out_of_line();
758            let handles_before = decoder.remaining_handles();
759            if let Some((inlined, num_bytes, num_handles)) =
760                fidl::encoding::decode_envelope_header(decoder, next_offset)?
761            {
762                let member_inline_size =
763                    <fidl::encoding::Vector<u8, 256> as fidl::encoding::TypeMarker>::inline_size(
764                        decoder.context,
765                    );
766                if inlined != (member_inline_size <= 4) {
767                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
768                }
769                let inner_offset;
770                let mut inner_depth = depth.clone();
771                if inlined {
772                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
773                    inner_offset = next_offset;
774                } else {
775                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
776                    inner_depth.increment()?;
777                }
778                let val_ref = self
779                    .interest_types
780                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Vector<u8, 256>, D));
781                fidl::decode!(fidl::encoding::Vector<u8, 256>, D, val_ref, decoder, inner_offset, inner_depth)?;
782                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
783                {
784                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
785                }
786                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
787                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
788                }
789            }
790
791            next_offset += envelope_size;
792            _next_ordinal_to_read += 1;
793            if next_offset >= end_offset {
794                return Ok(());
795            }
796
797            // Decode unknown envelopes for gaps in ordinals.
798            while _next_ordinal_to_read < 2 {
799                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
800                _next_ordinal_to_read += 1;
801                next_offset += envelope_size;
802            }
803
804            let next_out_of_line = decoder.next_out_of_line();
805            let handles_before = decoder.remaining_handles();
806            if let Some((inlined, num_bytes, num_handles)) =
807                fidl::encoding::decode_envelope_header(decoder, next_offset)?
808            {
809                let member_inline_size =
810                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
811                if inlined != (member_inline_size <= 4) {
812                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
813                }
814                let inner_offset;
815                let mut inner_depth = depth.clone();
816                if inlined {
817                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
818                    inner_offset = next_offset;
819                } else {
820                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
821                    inner_depth.increment()?;
822                }
823                let val_ref =
824                    self.interest_interface_id.get_or_insert_with(|| fidl::new_empty!(u64, D));
825                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
826                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
827                {
828                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
829                }
830                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
831                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
832                }
833            }
834
835            next_offset += envelope_size;
836
837            // Decode the remaining unknown envelopes.
838            while next_offset < end_offset {
839                _next_ordinal_to_read += 1;
840                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
841                next_offset += envelope_size;
842            }
843
844            Ok(())
845        }
846    }
847}