fidl_fuchsia_net_reachability__common/
fidl_fuchsia_net_reachability__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#[derive(Clone, Debug, Default, PartialEq)]
12pub struct MonitorOptions {
13    #[doc(hidden)]
14    pub __source_breaking: fidl::marker::SourceBreaking,
15}
16
17impl fidl::Persistable for MonitorOptions {}
18
19/// Information about network configuration and apparent reachability status
20/// of external networks.
21#[derive(Clone, Debug, Default, PartialEq)]
22pub struct Snapshot {
23    /// Signifies whether internet reachability is available.
24    pub internet_available: Option<bool>,
25    /// Indicates whether any default gateway is reachable at least via
26    /// link layer.
27    pub gateway_reachable: Option<bool>,
28    /// Indicates whether DNS services are functional via any configured
29    /// network.
30    pub dns_active: Option<bool>,
31    /// Indicates whether HTTP fetching is functional via any configured
32    /// network.
33    pub http_active: Option<bool>,
34    #[doc(hidden)]
35    pub __source_breaking: fidl::marker::SourceBreaking,
36}
37
38impl fidl::Persistable for Snapshot {}
39
40pub mod monitor_ordinals {
41    pub const SET_OPTIONS: u64 = 0x2e4e66abc4374253;
42    pub const WATCH: u64 = 0x381ea392fef3667f;
43}
44
45mod internal {
46    use super::*;
47
48    impl MonitorOptions {
49        #[inline(always)]
50        fn max_ordinal_present(&self) -> u64 {
51            0
52        }
53    }
54
55    impl fidl::encoding::ValueTypeMarker for MonitorOptions {
56        type Borrowed<'a> = &'a Self;
57        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
58            value
59        }
60    }
61
62    unsafe impl fidl::encoding::TypeMarker for MonitorOptions {
63        type Owned = Self;
64
65        #[inline(always)]
66        fn inline_align(_context: fidl::encoding::Context) -> usize {
67            8
68        }
69
70        #[inline(always)]
71        fn inline_size(_context: fidl::encoding::Context) -> usize {
72            16
73        }
74    }
75
76    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<MonitorOptions, D>
77        for &MonitorOptions
78    {
79        unsafe fn encode(
80            self,
81            encoder: &mut fidl::encoding::Encoder<'_, D>,
82            offset: usize,
83            mut depth: fidl::encoding::Depth,
84        ) -> fidl::Result<()> {
85            encoder.debug_check_bounds::<MonitorOptions>(offset);
86            // Vector header
87            let max_ordinal: u64 = self.max_ordinal_present();
88            encoder.write_num(max_ordinal, offset);
89            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
90            // Calling encoder.out_of_line_offset(0) is not allowed.
91            if max_ordinal == 0 {
92                return Ok(());
93            }
94            depth.increment()?;
95            let envelope_size = 8;
96            let bytes_len = max_ordinal as usize * envelope_size;
97            #[allow(unused_variables)]
98            let offset = encoder.out_of_line_offset(bytes_len);
99            let mut _prev_end_offset: usize = 0;
100
101            Ok(())
102        }
103    }
104
105    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MonitorOptions {
106        #[inline(always)]
107        fn new_empty() -> Self {
108            Self::default()
109        }
110
111        unsafe fn decode(
112            &mut self,
113            decoder: &mut fidl::encoding::Decoder<'_, D>,
114            offset: usize,
115            mut depth: fidl::encoding::Depth,
116        ) -> fidl::Result<()> {
117            decoder.debug_check_bounds::<Self>(offset);
118            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
119                None => return Err(fidl::Error::NotNullable),
120                Some(len) => len,
121            };
122            // Calling decoder.out_of_line_offset(0) is not allowed.
123            if len == 0 {
124                return Ok(());
125            };
126            depth.increment()?;
127            let envelope_size = 8;
128            let bytes_len = len * envelope_size;
129            let offset = decoder.out_of_line_offset(bytes_len)?;
130            // Decode the envelope for each type.
131            let mut _next_ordinal_to_read = 0;
132            let mut next_offset = offset;
133            let end_offset = offset + bytes_len;
134
135            // Decode the remaining unknown envelopes.
136            while next_offset < end_offset {
137                _next_ordinal_to_read += 1;
138                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
139                next_offset += envelope_size;
140            }
141
142            Ok(())
143        }
144    }
145
146    impl Snapshot {
147        #[inline(always)]
148        fn max_ordinal_present(&self) -> u64 {
149            if let Some(_) = self.http_active {
150                return 4;
151            }
152            if let Some(_) = self.dns_active {
153                return 3;
154            }
155            if let Some(_) = self.gateway_reachable {
156                return 2;
157            }
158            if let Some(_) = self.internet_available {
159                return 1;
160            }
161            0
162        }
163    }
164
165    impl fidl::encoding::ValueTypeMarker for Snapshot {
166        type Borrowed<'a> = &'a Self;
167        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
168            value
169        }
170    }
171
172    unsafe impl fidl::encoding::TypeMarker for Snapshot {
173        type Owned = Self;
174
175        #[inline(always)]
176        fn inline_align(_context: fidl::encoding::Context) -> usize {
177            8
178        }
179
180        #[inline(always)]
181        fn inline_size(_context: fidl::encoding::Context) -> usize {
182            16
183        }
184    }
185
186    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Snapshot, D> for &Snapshot {
187        unsafe fn encode(
188            self,
189            encoder: &mut fidl::encoding::Encoder<'_, D>,
190            offset: usize,
191            mut depth: fidl::encoding::Depth,
192        ) -> fidl::Result<()> {
193            encoder.debug_check_bounds::<Snapshot>(offset);
194            // Vector header
195            let max_ordinal: u64 = self.max_ordinal_present();
196            encoder.write_num(max_ordinal, offset);
197            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
198            // Calling encoder.out_of_line_offset(0) is not allowed.
199            if max_ordinal == 0 {
200                return Ok(());
201            }
202            depth.increment()?;
203            let envelope_size = 8;
204            let bytes_len = max_ordinal as usize * envelope_size;
205            #[allow(unused_variables)]
206            let offset = encoder.out_of_line_offset(bytes_len);
207            let mut _prev_end_offset: usize = 0;
208            if 1 > max_ordinal {
209                return Ok(());
210            }
211
212            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
213            // are envelope_size bytes.
214            let cur_offset: usize = (1 - 1) * envelope_size;
215
216            // Zero reserved fields.
217            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
218
219            // Safety:
220            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
221            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
222            //   envelope_size bytes, there is always sufficient room.
223            fidl::encoding::encode_in_envelope_optional::<bool, D>(
224                self.internet_available
225                    .as_ref()
226                    .map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
227                encoder,
228                offset + cur_offset,
229                depth,
230            )?;
231
232            _prev_end_offset = cur_offset + envelope_size;
233            if 2 > max_ordinal {
234                return Ok(());
235            }
236
237            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
238            // are envelope_size bytes.
239            let cur_offset: usize = (2 - 1) * envelope_size;
240
241            // Zero reserved fields.
242            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
243
244            // Safety:
245            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
246            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
247            //   envelope_size bytes, there is always sufficient room.
248            fidl::encoding::encode_in_envelope_optional::<bool, D>(
249                self.gateway_reachable
250                    .as_ref()
251                    .map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
252                encoder,
253                offset + cur_offset,
254                depth,
255            )?;
256
257            _prev_end_offset = cur_offset + envelope_size;
258            if 3 > max_ordinal {
259                return Ok(());
260            }
261
262            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
263            // are envelope_size bytes.
264            let cur_offset: usize = (3 - 1) * envelope_size;
265
266            // Zero reserved fields.
267            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
268
269            // Safety:
270            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
271            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
272            //   envelope_size bytes, there is always sufficient room.
273            fidl::encoding::encode_in_envelope_optional::<bool, D>(
274                self.dns_active.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
275                encoder,
276                offset + cur_offset,
277                depth,
278            )?;
279
280            _prev_end_offset = cur_offset + envelope_size;
281            if 4 > max_ordinal {
282                return Ok(());
283            }
284
285            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
286            // are envelope_size bytes.
287            let cur_offset: usize = (4 - 1) * envelope_size;
288
289            // Zero reserved fields.
290            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
291
292            // Safety:
293            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
294            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
295            //   envelope_size bytes, there is always sufficient room.
296            fidl::encoding::encode_in_envelope_optional::<bool, D>(
297                self.http_active.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
298                encoder,
299                offset + cur_offset,
300                depth,
301            )?;
302
303            _prev_end_offset = cur_offset + envelope_size;
304
305            Ok(())
306        }
307    }
308
309    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Snapshot {
310        #[inline(always)]
311        fn new_empty() -> Self {
312            Self::default()
313        }
314
315        unsafe fn decode(
316            &mut self,
317            decoder: &mut fidl::encoding::Decoder<'_, D>,
318            offset: usize,
319            mut depth: fidl::encoding::Depth,
320        ) -> fidl::Result<()> {
321            decoder.debug_check_bounds::<Self>(offset);
322            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
323                None => return Err(fidl::Error::NotNullable),
324                Some(len) => len,
325            };
326            // Calling decoder.out_of_line_offset(0) is not allowed.
327            if len == 0 {
328                return Ok(());
329            };
330            depth.increment()?;
331            let envelope_size = 8;
332            let bytes_len = len * envelope_size;
333            let offset = decoder.out_of_line_offset(bytes_len)?;
334            // Decode the envelope for each type.
335            let mut _next_ordinal_to_read = 0;
336            let mut next_offset = offset;
337            let end_offset = offset + bytes_len;
338            _next_ordinal_to_read += 1;
339            if next_offset >= end_offset {
340                return Ok(());
341            }
342
343            // Decode unknown envelopes for gaps in ordinals.
344            while _next_ordinal_to_read < 1 {
345                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
346                _next_ordinal_to_read += 1;
347                next_offset += envelope_size;
348            }
349
350            let next_out_of_line = decoder.next_out_of_line();
351            let handles_before = decoder.remaining_handles();
352            if let Some((inlined, num_bytes, num_handles)) =
353                fidl::encoding::decode_envelope_header(decoder, next_offset)?
354            {
355                let member_inline_size =
356                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
357                if inlined != (member_inline_size <= 4) {
358                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
359                }
360                let inner_offset;
361                let mut inner_depth = depth.clone();
362                if inlined {
363                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
364                    inner_offset = next_offset;
365                } else {
366                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
367                    inner_depth.increment()?;
368                }
369                let val_ref =
370                    self.internet_available.get_or_insert_with(|| fidl::new_empty!(bool, D));
371                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
372                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
373                {
374                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
375                }
376                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
377                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
378                }
379            }
380
381            next_offset += envelope_size;
382            _next_ordinal_to_read += 1;
383            if next_offset >= end_offset {
384                return Ok(());
385            }
386
387            // Decode unknown envelopes for gaps in ordinals.
388            while _next_ordinal_to_read < 2 {
389                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
390                _next_ordinal_to_read += 1;
391                next_offset += envelope_size;
392            }
393
394            let next_out_of_line = decoder.next_out_of_line();
395            let handles_before = decoder.remaining_handles();
396            if let Some((inlined, num_bytes, num_handles)) =
397                fidl::encoding::decode_envelope_header(decoder, next_offset)?
398            {
399                let member_inline_size =
400                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
401                if inlined != (member_inline_size <= 4) {
402                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
403                }
404                let inner_offset;
405                let mut inner_depth = depth.clone();
406                if inlined {
407                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
408                    inner_offset = next_offset;
409                } else {
410                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
411                    inner_depth.increment()?;
412                }
413                let val_ref =
414                    self.gateway_reachable.get_or_insert_with(|| fidl::new_empty!(bool, D));
415                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
416                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
417                {
418                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
419                }
420                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
421                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
422                }
423            }
424
425            next_offset += envelope_size;
426            _next_ordinal_to_read += 1;
427            if next_offset >= end_offset {
428                return Ok(());
429            }
430
431            // Decode unknown envelopes for gaps in ordinals.
432            while _next_ordinal_to_read < 3 {
433                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
434                _next_ordinal_to_read += 1;
435                next_offset += envelope_size;
436            }
437
438            let next_out_of_line = decoder.next_out_of_line();
439            let handles_before = decoder.remaining_handles();
440            if let Some((inlined, num_bytes, num_handles)) =
441                fidl::encoding::decode_envelope_header(decoder, next_offset)?
442            {
443                let member_inline_size =
444                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
445                if inlined != (member_inline_size <= 4) {
446                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
447                }
448                let inner_offset;
449                let mut inner_depth = depth.clone();
450                if inlined {
451                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
452                    inner_offset = next_offset;
453                } else {
454                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
455                    inner_depth.increment()?;
456                }
457                let val_ref = self.dns_active.get_or_insert_with(|| fidl::new_empty!(bool, D));
458                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
459                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
460                {
461                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
462                }
463                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
464                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
465                }
466            }
467
468            next_offset += envelope_size;
469            _next_ordinal_to_read += 1;
470            if next_offset >= end_offset {
471                return Ok(());
472            }
473
474            // Decode unknown envelopes for gaps in ordinals.
475            while _next_ordinal_to_read < 4 {
476                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
477                _next_ordinal_to_read += 1;
478                next_offset += envelope_size;
479            }
480
481            let next_out_of_line = decoder.next_out_of_line();
482            let handles_before = decoder.remaining_handles();
483            if let Some((inlined, num_bytes, num_handles)) =
484                fidl::encoding::decode_envelope_header(decoder, next_offset)?
485            {
486                let member_inline_size =
487                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
488                if inlined != (member_inline_size <= 4) {
489                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
490                }
491                let inner_offset;
492                let mut inner_depth = depth.clone();
493                if inlined {
494                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
495                    inner_offset = next_offset;
496                } else {
497                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
498                    inner_depth.increment()?;
499                }
500                let val_ref = self.http_active.get_or_insert_with(|| fidl::new_empty!(bool, D));
501                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
502                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
503                {
504                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
505                }
506                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
507                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
508                }
509            }
510
511            next_offset += envelope_size;
512
513            // Decode the remaining unknown envelopes.
514            while next_offset < end_offset {
515                _next_ordinal_to_read += 1;
516                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
517                next_offset += envelope_size;
518            }
519
520            Ok(())
521        }
522    }
523}