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