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