fidl_fuchsia_location_position__common/
fidl_fuchsia_location_position__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, PartialEq)]
12pub struct EmergencyProviderGetCurrentResponse {
13    pub position: Position,
14}
15
16impl fidl::Persistable for EmergencyProviderGetCurrentResponse {}
17
18/// Describes a position on Earth.
19///
20/// A fully-specified position includes latitude and longitude,
21/// as well a radius of accuracy of the current position in
22/// the horizontal plane, and the current altitude.
23///
24/// Note that only the latitude and longitude are guaranteed
25/// to be present. The remaining fields, if present, are contained
26/// within `extras`.
27#[derive(Clone, Debug, PartialEq)]
28pub struct Position {
29    pub latitude: f64,
30    pub longitude: f64,
31    pub extras: PositionExtras,
32}
33
34impl fidl::Persistable for Position {}
35
36/// Extra information about a position on Earth.
37///
38/// The radius of accuracy may incorporate any sources of
39/// uncertainty available to the positioning system. This may include,
40/// for example, radio propagation models, triangulation error, and
41/// motion compensation.
42///
43/// Note that all extras are optional.
44#[derive(Clone, Debug, Default, PartialEq)]
45pub struct PositionExtras {
46    pub accuracy_meters: Option<f64>,
47    pub altitude_meters: Option<f64>,
48    #[doc(hidden)]
49    pub __source_breaking: fidl::marker::SourceBreaking,
50}
51
52impl fidl::Persistable for PositionExtras {}
53
54pub mod emergency_provider_ordinals {
55    pub const GET_CURRENT: u64 = 0x69243da09135d131;
56}
57
58mod internal {
59    use super::*;
60
61    impl fidl::encoding::ValueTypeMarker for EmergencyProviderGetCurrentResponse {
62        type Borrowed<'a> = &'a Self;
63        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
64            value
65        }
66    }
67
68    unsafe impl fidl::encoding::TypeMarker for EmergencyProviderGetCurrentResponse {
69        type Owned = Self;
70
71        #[inline(always)]
72        fn inline_align(_context: fidl::encoding::Context) -> usize {
73            8
74        }
75
76        #[inline(always)]
77        fn inline_size(_context: fidl::encoding::Context) -> usize {
78            32
79        }
80    }
81
82    unsafe impl<D: fidl::encoding::ResourceDialect>
83        fidl::encoding::Encode<EmergencyProviderGetCurrentResponse, D>
84        for &EmergencyProviderGetCurrentResponse
85    {
86        #[inline]
87        unsafe fn encode(
88            self,
89            encoder: &mut fidl::encoding::Encoder<'_, D>,
90            offset: usize,
91            _depth: fidl::encoding::Depth,
92        ) -> fidl::Result<()> {
93            encoder.debug_check_bounds::<EmergencyProviderGetCurrentResponse>(offset);
94            // Delegate to tuple encoding.
95            fidl::encoding::Encode::<EmergencyProviderGetCurrentResponse, D>::encode(
96                (<Position as fidl::encoding::ValueTypeMarker>::borrow(&self.position),),
97                encoder,
98                offset,
99                _depth,
100            )
101        }
102    }
103    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Position, D>>
104        fidl::encoding::Encode<EmergencyProviderGetCurrentResponse, D> for (T0,)
105    {
106        #[inline]
107        unsafe fn encode(
108            self,
109            encoder: &mut fidl::encoding::Encoder<'_, D>,
110            offset: usize,
111            depth: fidl::encoding::Depth,
112        ) -> fidl::Result<()> {
113            encoder.debug_check_bounds::<EmergencyProviderGetCurrentResponse>(offset);
114            // Zero out padding regions. There's no need to apply masks
115            // because the unmasked parts will be overwritten by fields.
116            // Write the fields.
117            self.0.encode(encoder, offset + 0, depth)?;
118            Ok(())
119        }
120    }
121
122    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
123        for EmergencyProviderGetCurrentResponse
124    {
125        #[inline(always)]
126        fn new_empty() -> Self {
127            Self { position: fidl::new_empty!(Position, D) }
128        }
129
130        #[inline]
131        unsafe fn decode(
132            &mut self,
133            decoder: &mut fidl::encoding::Decoder<'_, D>,
134            offset: usize,
135            _depth: fidl::encoding::Depth,
136        ) -> fidl::Result<()> {
137            decoder.debug_check_bounds::<Self>(offset);
138            // Verify that padding bytes are zero.
139            fidl::decode!(Position, D, &mut self.position, decoder, offset + 0, _depth)?;
140            Ok(())
141        }
142    }
143
144    impl fidl::encoding::ValueTypeMarker for Position {
145        type Borrowed<'a> = &'a Self;
146        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
147            value
148        }
149    }
150
151    unsafe impl fidl::encoding::TypeMarker for Position {
152        type Owned = Self;
153
154        #[inline(always)]
155        fn inline_align(_context: fidl::encoding::Context) -> usize {
156            8
157        }
158
159        #[inline(always)]
160        fn inline_size(_context: fidl::encoding::Context) -> usize {
161            32
162        }
163    }
164
165    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Position, D> for &Position {
166        #[inline]
167        unsafe fn encode(
168            self,
169            encoder: &mut fidl::encoding::Encoder<'_, D>,
170            offset: usize,
171            _depth: fidl::encoding::Depth,
172        ) -> fidl::Result<()> {
173            encoder.debug_check_bounds::<Position>(offset);
174            // Delegate to tuple encoding.
175            fidl::encoding::Encode::<Position, D>::encode(
176                (
177                    <f64 as fidl::encoding::ValueTypeMarker>::borrow(&self.latitude),
178                    <f64 as fidl::encoding::ValueTypeMarker>::borrow(&self.longitude),
179                    <PositionExtras as fidl::encoding::ValueTypeMarker>::borrow(&self.extras),
180                ),
181                encoder,
182                offset,
183                _depth,
184            )
185        }
186    }
187    unsafe impl<
188            D: fidl::encoding::ResourceDialect,
189            T0: fidl::encoding::Encode<f64, D>,
190            T1: fidl::encoding::Encode<f64, D>,
191            T2: fidl::encoding::Encode<PositionExtras, D>,
192        > fidl::encoding::Encode<Position, D> for (T0, T1, T2)
193    {
194        #[inline]
195        unsafe fn encode(
196            self,
197            encoder: &mut fidl::encoding::Encoder<'_, D>,
198            offset: usize,
199            depth: fidl::encoding::Depth,
200        ) -> fidl::Result<()> {
201            encoder.debug_check_bounds::<Position>(offset);
202            // Zero out padding regions. There's no need to apply masks
203            // because the unmasked parts will be overwritten by fields.
204            // Write the fields.
205            self.0.encode(encoder, offset + 0, depth)?;
206            self.1.encode(encoder, offset + 8, depth)?;
207            self.2.encode(encoder, offset + 16, depth)?;
208            Ok(())
209        }
210    }
211
212    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Position {
213        #[inline(always)]
214        fn new_empty() -> Self {
215            Self {
216                latitude: fidl::new_empty!(f64, D),
217                longitude: fidl::new_empty!(f64, D),
218                extras: fidl::new_empty!(PositionExtras, D),
219            }
220        }
221
222        #[inline]
223        unsafe fn decode(
224            &mut self,
225            decoder: &mut fidl::encoding::Decoder<'_, D>,
226            offset: usize,
227            _depth: fidl::encoding::Depth,
228        ) -> fidl::Result<()> {
229            decoder.debug_check_bounds::<Self>(offset);
230            // Verify that padding bytes are zero.
231            fidl::decode!(f64, D, &mut self.latitude, decoder, offset + 0, _depth)?;
232            fidl::decode!(f64, D, &mut self.longitude, decoder, offset + 8, _depth)?;
233            fidl::decode!(PositionExtras, D, &mut self.extras, decoder, offset + 16, _depth)?;
234            Ok(())
235        }
236    }
237
238    impl PositionExtras {
239        #[inline(always)]
240        fn max_ordinal_present(&self) -> u64 {
241            if let Some(_) = self.altitude_meters {
242                return 2;
243            }
244            if let Some(_) = self.accuracy_meters {
245                return 1;
246            }
247            0
248        }
249    }
250
251    impl fidl::encoding::ValueTypeMarker for PositionExtras {
252        type Borrowed<'a> = &'a Self;
253        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
254            value
255        }
256    }
257
258    unsafe impl fidl::encoding::TypeMarker for PositionExtras {
259        type Owned = Self;
260
261        #[inline(always)]
262        fn inline_align(_context: fidl::encoding::Context) -> usize {
263            8
264        }
265
266        #[inline(always)]
267        fn inline_size(_context: fidl::encoding::Context) -> usize {
268            16
269        }
270    }
271
272    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<PositionExtras, D>
273        for &PositionExtras
274    {
275        unsafe fn encode(
276            self,
277            encoder: &mut fidl::encoding::Encoder<'_, D>,
278            offset: usize,
279            mut depth: fidl::encoding::Depth,
280        ) -> fidl::Result<()> {
281            encoder.debug_check_bounds::<PositionExtras>(offset);
282            // Vector header
283            let max_ordinal: u64 = self.max_ordinal_present();
284            encoder.write_num(max_ordinal, offset);
285            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
286            // Calling encoder.out_of_line_offset(0) is not allowed.
287            if max_ordinal == 0 {
288                return Ok(());
289            }
290            depth.increment()?;
291            let envelope_size = 8;
292            let bytes_len = max_ordinal as usize * envelope_size;
293            #[allow(unused_variables)]
294            let offset = encoder.out_of_line_offset(bytes_len);
295            let mut _prev_end_offset: usize = 0;
296            if 1 > max_ordinal {
297                return Ok(());
298            }
299
300            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
301            // are envelope_size bytes.
302            let cur_offset: usize = (1 - 1) * envelope_size;
303
304            // Zero reserved fields.
305            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
306
307            // Safety:
308            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
309            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
310            //   envelope_size bytes, there is always sufficient room.
311            fidl::encoding::encode_in_envelope_optional::<f64, D>(
312                self.accuracy_meters.as_ref().map(<f64 as fidl::encoding::ValueTypeMarker>::borrow),
313                encoder,
314                offset + cur_offset,
315                depth,
316            )?;
317
318            _prev_end_offset = cur_offset + envelope_size;
319            if 2 > max_ordinal {
320                return Ok(());
321            }
322
323            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
324            // are envelope_size bytes.
325            let cur_offset: usize = (2 - 1) * envelope_size;
326
327            // Zero reserved fields.
328            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
329
330            // Safety:
331            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
332            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
333            //   envelope_size bytes, there is always sufficient room.
334            fidl::encoding::encode_in_envelope_optional::<f64, D>(
335                self.altitude_meters.as_ref().map(<f64 as fidl::encoding::ValueTypeMarker>::borrow),
336                encoder,
337                offset + cur_offset,
338                depth,
339            )?;
340
341            _prev_end_offset = cur_offset + envelope_size;
342
343            Ok(())
344        }
345    }
346
347    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PositionExtras {
348        #[inline(always)]
349        fn new_empty() -> Self {
350            Self::default()
351        }
352
353        unsafe fn decode(
354            &mut self,
355            decoder: &mut fidl::encoding::Decoder<'_, D>,
356            offset: usize,
357            mut depth: fidl::encoding::Depth,
358        ) -> fidl::Result<()> {
359            decoder.debug_check_bounds::<Self>(offset);
360            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
361                None => return Err(fidl::Error::NotNullable),
362                Some(len) => len,
363            };
364            // Calling decoder.out_of_line_offset(0) is not allowed.
365            if len == 0 {
366                return Ok(());
367            };
368            depth.increment()?;
369            let envelope_size = 8;
370            let bytes_len = len * envelope_size;
371            let offset = decoder.out_of_line_offset(bytes_len)?;
372            // Decode the envelope for each type.
373            let mut _next_ordinal_to_read = 0;
374            let mut next_offset = offset;
375            let end_offset = offset + bytes_len;
376            _next_ordinal_to_read += 1;
377            if next_offset >= end_offset {
378                return Ok(());
379            }
380
381            // Decode unknown envelopes for gaps in ordinals.
382            while _next_ordinal_to_read < 1 {
383                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
384                _next_ordinal_to_read += 1;
385                next_offset += envelope_size;
386            }
387
388            let next_out_of_line = decoder.next_out_of_line();
389            let handles_before = decoder.remaining_handles();
390            if let Some((inlined, num_bytes, num_handles)) =
391                fidl::encoding::decode_envelope_header(decoder, next_offset)?
392            {
393                let member_inline_size =
394                    <f64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
395                if inlined != (member_inline_size <= 4) {
396                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
397                }
398                let inner_offset;
399                let mut inner_depth = depth.clone();
400                if inlined {
401                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
402                    inner_offset = next_offset;
403                } else {
404                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
405                    inner_depth.increment()?;
406                }
407                let val_ref = self.accuracy_meters.get_or_insert_with(|| fidl::new_empty!(f64, D));
408                fidl::decode!(f64, D, val_ref, decoder, inner_offset, inner_depth)?;
409                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
410                {
411                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
412                }
413                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
414                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
415                }
416            }
417
418            next_offset += envelope_size;
419            _next_ordinal_to_read += 1;
420            if next_offset >= end_offset {
421                return Ok(());
422            }
423
424            // Decode unknown envelopes for gaps in ordinals.
425            while _next_ordinal_to_read < 2 {
426                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
427                _next_ordinal_to_read += 1;
428                next_offset += envelope_size;
429            }
430
431            let next_out_of_line = decoder.next_out_of_line();
432            let handles_before = decoder.remaining_handles();
433            if let Some((inlined, num_bytes, num_handles)) =
434                fidl::encoding::decode_envelope_header(decoder, next_offset)?
435            {
436                let member_inline_size =
437                    <f64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
438                if inlined != (member_inline_size <= 4) {
439                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
440                }
441                let inner_offset;
442                let mut inner_depth = depth.clone();
443                if inlined {
444                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
445                    inner_offset = next_offset;
446                } else {
447                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
448                    inner_depth.increment()?;
449                }
450                let val_ref = self.altitude_meters.get_or_insert_with(|| fidl::new_empty!(f64, D));
451                fidl::decode!(f64, D, val_ref, decoder, inner_offset, inner_depth)?;
452                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
453                {
454                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
455                }
456                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
457                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
458                }
459            }
460
461            next_offset += envelope_size;
462
463            // Decode the remaining unknown envelopes.
464            while next_offset < end_offset {
465                _next_ordinal_to_read += 1;
466                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
467                next_offset += envelope_size;
468            }
469
470            Ok(())
471        }
472    }
473}