fidl_fuchsia_netstack_persistence_common/
fidl_fuchsia_netstack_persistence_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 number of bytes in the secret key used for opaque IIDs.
12pub const IID_SECRET_KEY_BYTES: u64 = 32;
13
14/// State that the netstack keeps in persistent storage.
15#[derive(Clone, Debug, Default, PartialEq)]
16pub struct State {
17    /// The secret key used to generate opaque IIDs for use in stable SLAAC
18    /// addresses, as defined in [RFC 7217 section 5].
19    ///
20    /// [RFC 7217 section 5]: https://tools.ietf.org/html/rfc7217/#section-5
21    pub opaque_iid_secret_key: Option<[u8; 32]>,
22    #[doc(hidden)]
23    pub __source_breaking: fidl::marker::SourceBreaking,
24}
25
26impl fidl::Persistable for State {}
27
28mod internal {
29    use super::*;
30
31    impl State {
32        #[inline(always)]
33        fn max_ordinal_present(&self) -> u64 {
34            if let Some(_) = self.opaque_iid_secret_key {
35                return 1;
36            }
37            0
38        }
39    }
40
41    impl fidl::encoding::ValueTypeMarker for State {
42        type Borrowed<'a> = &'a Self;
43        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
44            value
45        }
46    }
47
48    unsafe impl fidl::encoding::TypeMarker for State {
49        type Owned = Self;
50
51        #[inline(always)]
52        fn inline_align(_context: fidl::encoding::Context) -> usize {
53            8
54        }
55
56        #[inline(always)]
57        fn inline_size(_context: fidl::encoding::Context) -> usize {
58            16
59        }
60    }
61
62    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<State, D> for &State {
63        unsafe fn encode(
64            self,
65            encoder: &mut fidl::encoding::Encoder<'_, D>,
66            offset: usize,
67            mut depth: fidl::encoding::Depth,
68        ) -> fidl::Result<()> {
69            encoder.debug_check_bounds::<State>(offset);
70            // Vector header
71            let max_ordinal: u64 = self.max_ordinal_present();
72            encoder.write_num(max_ordinal, offset);
73            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
74            // Calling encoder.out_of_line_offset(0) is not allowed.
75            if max_ordinal == 0 {
76                return Ok(());
77            }
78            depth.increment()?;
79            let envelope_size = 8;
80            let bytes_len = max_ordinal as usize * envelope_size;
81            #[allow(unused_variables)]
82            let offset = encoder.out_of_line_offset(bytes_len);
83            let mut _prev_end_offset: usize = 0;
84            if 1 > max_ordinal {
85                return Ok(());
86            }
87
88            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
89            // are envelope_size bytes.
90            let cur_offset: usize = (1 - 1) * envelope_size;
91
92            // Zero reserved fields.
93            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
94
95            // Safety:
96            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
97            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
98            //   envelope_size bytes, there is always sufficient room.
99            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Array<u8, 32>, D>(
100                self.opaque_iid_secret_key.as_ref().map(
101                    <fidl::encoding::Array<u8, 32> as fidl::encoding::ValueTypeMarker>::borrow,
102                ),
103                encoder,
104                offset + cur_offset,
105                depth,
106            )?;
107
108            _prev_end_offset = cur_offset + envelope_size;
109
110            Ok(())
111        }
112    }
113
114    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for State {
115        #[inline(always)]
116        fn new_empty() -> Self {
117            Self::default()
118        }
119
120        unsafe fn decode(
121            &mut self,
122            decoder: &mut fidl::encoding::Decoder<'_, D>,
123            offset: usize,
124            mut depth: fidl::encoding::Depth,
125        ) -> fidl::Result<()> {
126            decoder.debug_check_bounds::<Self>(offset);
127            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
128                None => return Err(fidl::Error::NotNullable),
129                Some(len) => len,
130            };
131            // Calling decoder.out_of_line_offset(0) is not allowed.
132            if len == 0 {
133                return Ok(());
134            };
135            depth.increment()?;
136            let envelope_size = 8;
137            let bytes_len = len * envelope_size;
138            let offset = decoder.out_of_line_offset(bytes_len)?;
139            // Decode the envelope for each type.
140            let mut _next_ordinal_to_read = 0;
141            let mut next_offset = offset;
142            let end_offset = offset + bytes_len;
143            _next_ordinal_to_read += 1;
144            if next_offset >= end_offset {
145                return Ok(());
146            }
147
148            // Decode unknown envelopes for gaps in ordinals.
149            while _next_ordinal_to_read < 1 {
150                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
151                _next_ordinal_to_read += 1;
152                next_offset += envelope_size;
153            }
154
155            let next_out_of_line = decoder.next_out_of_line();
156            let handles_before = decoder.remaining_handles();
157            if let Some((inlined, num_bytes, num_handles)) =
158                fidl::encoding::decode_envelope_header(decoder, next_offset)?
159            {
160                let member_inline_size =
161                    <fidl::encoding::Array<u8, 32> as fidl::encoding::TypeMarker>::inline_size(
162                        decoder.context,
163                    );
164                if inlined != (member_inline_size <= 4) {
165                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
166                }
167                let inner_offset;
168                let mut inner_depth = depth.clone();
169                if inlined {
170                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
171                    inner_offset = next_offset;
172                } else {
173                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
174                    inner_depth.increment()?;
175                }
176                let val_ref = self
177                    .opaque_iid_secret_key
178                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Array<u8, 32>, D));
179                fidl::decode!(fidl::encoding::Array<u8, 32>, D, val_ref, decoder, inner_offset, inner_depth)?;
180                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
181                {
182                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
183                }
184                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
185                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
186                }
187            }
188
189            next_offset += envelope_size;
190
191            // Decode the remaining unknown envelopes.
192            while next_offset < end_offset {
193                _next_ordinal_to_read += 1;
194                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
195                next_offset += envelope_size;
196            }
197
198            Ok(())
199        }
200    }
201}