fidl_fuchsia_lightsensor__common/
fidl_fuchsia_lightsensor__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/// Possible error results from API calls.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(u32)]
14pub enum Error {
15    /// The input provided to the API was outside of the valid range of input, or required
16    /// parameters were missing from a table.
17    InvalidInput = 1,
18}
19
20impl Error {
21    #[inline]
22    pub fn from_primitive(prim: u32) -> Option<Self> {
23        match prim {
24            1 => Some(Self::InvalidInput),
25            _ => None,
26        }
27    }
28
29    #[inline]
30    pub const fn into_primitive(self) -> u32 {
31        self as u32
32    }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
36pub struct CalibratorCalibrateRequest {
37    pub data: Rgbc,
38}
39
40impl fidl::Persistable for CalibratorCalibrateRequest {}
41
42#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
43pub struct CalibratorCalibrateResponse {
44    pub data: Rgbc,
45}
46
47impl fidl::Persistable for CalibratorCalibrateResponse {}
48
49/// Device-specific intensity values for the color channels in the light sensor.
50#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
51pub struct Rgbc {
52    /// Intensity of red light measured by the light sensor.
53    pub red_intensity: f32,
54    /// Intensity of green light measured by the light sensor.
55    pub green_intensity: f32,
56    /// Intensity of blue light measured by the light sensor.
57    pub blue_intensity: f32,
58    /// Intensity of clear light measured by the light sensor.
59    pub clear_intensity: f32,
60}
61
62impl fidl::Persistable for Rgbc {}
63
64#[derive(Clone, Debug, PartialEq)]
65pub struct SensorWatchResponse {
66    pub data: LightSensorData,
67}
68
69impl fidl::Persistable for SensorWatchResponse {}
70
71#[derive(Clone, Debug, Default, PartialEq)]
72pub struct LightSensorData {
73    /// Light intensities measured by the light sensor in raw sensor counts. The
74    /// value will vary depending on the specific hardware used. This field will
75    /// always be populated.
76    pub rgbc: Option<Rgbc>,
77    /// A weighted sum of the RGBC intensities. This field will always be
78    /// populated.
79    pub calculated_lux: Option<f32>,
80    /// The color temperature of the measured light. This field will always be
81    /// populated.
82    pub correlated_color_temperature: Option<f32>,
83    /// Light intensities measured by the light sensor in the International
84    /// System (SI) units of uW/cm^2. This field will always be populated.
85    pub si_rgbc: Option<Rgbc>,
86    /// Whether or not the si_rgbc, calculated_lux and
87    /// correlated_color_temperature values are calibrated. This field will
88    /// always be populated.
89    pub is_calibrated: Option<bool>,
90    #[doc(hidden)]
91    pub __source_breaking: fidl::marker::SourceBreaking,
92}
93
94impl fidl::Persistable for LightSensorData {}
95
96mod internal {
97    use super::*;
98    unsafe impl fidl::encoding::TypeMarker for Error {
99        type Owned = Self;
100
101        #[inline(always)]
102        fn inline_align(_context: fidl::encoding::Context) -> usize {
103            std::mem::align_of::<u32>()
104        }
105
106        #[inline(always)]
107        fn inline_size(_context: fidl::encoding::Context) -> usize {
108            std::mem::size_of::<u32>()
109        }
110
111        #[inline(always)]
112        fn encode_is_copy() -> bool {
113            true
114        }
115
116        #[inline(always)]
117        fn decode_is_copy() -> bool {
118            false
119        }
120    }
121
122    impl fidl::encoding::ValueTypeMarker for Error {
123        type Borrowed<'a> = Self;
124        #[inline(always)]
125        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
126            *value
127        }
128    }
129
130    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
131        #[inline]
132        unsafe fn encode(
133            self,
134            encoder: &mut fidl::encoding::Encoder<'_, D>,
135            offset: usize,
136            _depth: fidl::encoding::Depth,
137        ) -> fidl::Result<()> {
138            encoder.debug_check_bounds::<Self>(offset);
139            encoder.write_num(self.into_primitive(), offset);
140            Ok(())
141        }
142    }
143
144    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
145        #[inline(always)]
146        fn new_empty() -> Self {
147            Self::InvalidInput
148        }
149
150        #[inline]
151        unsafe fn decode(
152            &mut self,
153            decoder: &mut fidl::encoding::Decoder<'_, D>,
154            offset: usize,
155            _depth: fidl::encoding::Depth,
156        ) -> fidl::Result<()> {
157            decoder.debug_check_bounds::<Self>(offset);
158            let prim = decoder.read_num::<u32>(offset);
159
160            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
161            Ok(())
162        }
163    }
164
165    impl fidl::encoding::ValueTypeMarker for CalibratorCalibrateRequest {
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 CalibratorCalibrateRequest {
173        type Owned = Self;
174
175        #[inline(always)]
176        fn inline_align(_context: fidl::encoding::Context) -> usize {
177            4
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>
187        fidl::encoding::Encode<CalibratorCalibrateRequest, D> for &CalibratorCalibrateRequest
188    {
189        #[inline]
190        unsafe fn encode(
191            self,
192            encoder: &mut fidl::encoding::Encoder<'_, D>,
193            offset: usize,
194            _depth: fidl::encoding::Depth,
195        ) -> fidl::Result<()> {
196            encoder.debug_check_bounds::<CalibratorCalibrateRequest>(offset);
197            // Delegate to tuple encoding.
198            fidl::encoding::Encode::<CalibratorCalibrateRequest, D>::encode(
199                (<Rgbc as fidl::encoding::ValueTypeMarker>::borrow(&self.data),),
200                encoder,
201                offset,
202                _depth,
203            )
204        }
205    }
206    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Rgbc, D>>
207        fidl::encoding::Encode<CalibratorCalibrateRequest, D> for (T0,)
208    {
209        #[inline]
210        unsafe fn encode(
211            self,
212            encoder: &mut fidl::encoding::Encoder<'_, D>,
213            offset: usize,
214            depth: fidl::encoding::Depth,
215        ) -> fidl::Result<()> {
216            encoder.debug_check_bounds::<CalibratorCalibrateRequest>(offset);
217            // Zero out padding regions. There's no need to apply masks
218            // because the unmasked parts will be overwritten by fields.
219            // Write the fields.
220            self.0.encode(encoder, offset + 0, depth)?;
221            Ok(())
222        }
223    }
224
225    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
226        for CalibratorCalibrateRequest
227    {
228        #[inline(always)]
229        fn new_empty() -> Self {
230            Self { data: fidl::new_empty!(Rgbc, D) }
231        }
232
233        #[inline]
234        unsafe fn decode(
235            &mut self,
236            decoder: &mut fidl::encoding::Decoder<'_, D>,
237            offset: usize,
238            _depth: fidl::encoding::Depth,
239        ) -> fidl::Result<()> {
240            decoder.debug_check_bounds::<Self>(offset);
241            // Verify that padding bytes are zero.
242            fidl::decode!(Rgbc, D, &mut self.data, decoder, offset + 0, _depth)?;
243            Ok(())
244        }
245    }
246
247    impl fidl::encoding::ValueTypeMarker for CalibratorCalibrateResponse {
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 CalibratorCalibrateResponse {
255        type Owned = Self;
256
257        #[inline(always)]
258        fn inline_align(_context: fidl::encoding::Context) -> usize {
259            4
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>
269        fidl::encoding::Encode<CalibratorCalibrateResponse, D> for &CalibratorCalibrateResponse
270    {
271        #[inline]
272        unsafe fn encode(
273            self,
274            encoder: &mut fidl::encoding::Encoder<'_, D>,
275            offset: usize,
276            _depth: fidl::encoding::Depth,
277        ) -> fidl::Result<()> {
278            encoder.debug_check_bounds::<CalibratorCalibrateResponse>(offset);
279            // Delegate to tuple encoding.
280            fidl::encoding::Encode::<CalibratorCalibrateResponse, D>::encode(
281                (<Rgbc as fidl::encoding::ValueTypeMarker>::borrow(&self.data),),
282                encoder,
283                offset,
284                _depth,
285            )
286        }
287    }
288    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Rgbc, D>>
289        fidl::encoding::Encode<CalibratorCalibrateResponse, D> for (T0,)
290    {
291        #[inline]
292        unsafe fn encode(
293            self,
294            encoder: &mut fidl::encoding::Encoder<'_, D>,
295            offset: usize,
296            depth: fidl::encoding::Depth,
297        ) -> fidl::Result<()> {
298            encoder.debug_check_bounds::<CalibratorCalibrateResponse>(offset);
299            // Zero out padding regions. There's no need to apply masks
300            // because the unmasked parts will be overwritten by fields.
301            // Write the fields.
302            self.0.encode(encoder, offset + 0, depth)?;
303            Ok(())
304        }
305    }
306
307    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
308        for CalibratorCalibrateResponse
309    {
310        #[inline(always)]
311        fn new_empty() -> Self {
312            Self { data: fidl::new_empty!(Rgbc, D) }
313        }
314
315        #[inline]
316        unsafe fn decode(
317            &mut self,
318            decoder: &mut fidl::encoding::Decoder<'_, D>,
319            offset: usize,
320            _depth: fidl::encoding::Depth,
321        ) -> fidl::Result<()> {
322            decoder.debug_check_bounds::<Self>(offset);
323            // Verify that padding bytes are zero.
324            fidl::decode!(Rgbc, D, &mut self.data, decoder, offset + 0, _depth)?;
325            Ok(())
326        }
327    }
328
329    impl fidl::encoding::ValueTypeMarker for Rgbc {
330        type Borrowed<'a> = &'a Self;
331        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
332            value
333        }
334    }
335
336    unsafe impl fidl::encoding::TypeMarker for Rgbc {
337        type Owned = Self;
338
339        #[inline(always)]
340        fn inline_align(_context: fidl::encoding::Context) -> usize {
341            4
342        }
343
344        #[inline(always)]
345        fn inline_size(_context: fidl::encoding::Context) -> usize {
346            16
347        }
348    }
349
350    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Rgbc, D> for &Rgbc {
351        #[inline]
352        unsafe fn encode(
353            self,
354            encoder: &mut fidl::encoding::Encoder<'_, D>,
355            offset: usize,
356            _depth: fidl::encoding::Depth,
357        ) -> fidl::Result<()> {
358            encoder.debug_check_bounds::<Rgbc>(offset);
359            // Delegate to tuple encoding.
360            fidl::encoding::Encode::<Rgbc, D>::encode(
361                (
362                    <f32 as fidl::encoding::ValueTypeMarker>::borrow(&self.red_intensity),
363                    <f32 as fidl::encoding::ValueTypeMarker>::borrow(&self.green_intensity),
364                    <f32 as fidl::encoding::ValueTypeMarker>::borrow(&self.blue_intensity),
365                    <f32 as fidl::encoding::ValueTypeMarker>::borrow(&self.clear_intensity),
366                ),
367                encoder,
368                offset,
369                _depth,
370            )
371        }
372    }
373    unsafe impl<
374            D: fidl::encoding::ResourceDialect,
375            T0: fidl::encoding::Encode<f32, D>,
376            T1: fidl::encoding::Encode<f32, D>,
377            T2: fidl::encoding::Encode<f32, D>,
378            T3: fidl::encoding::Encode<f32, D>,
379        > fidl::encoding::Encode<Rgbc, D> for (T0, T1, T2, T3)
380    {
381        #[inline]
382        unsafe fn encode(
383            self,
384            encoder: &mut fidl::encoding::Encoder<'_, D>,
385            offset: usize,
386            depth: fidl::encoding::Depth,
387        ) -> fidl::Result<()> {
388            encoder.debug_check_bounds::<Rgbc>(offset);
389            // Zero out padding regions. There's no need to apply masks
390            // because the unmasked parts will be overwritten by fields.
391            // Write the fields.
392            self.0.encode(encoder, offset + 0, depth)?;
393            self.1.encode(encoder, offset + 4, depth)?;
394            self.2.encode(encoder, offset + 8, depth)?;
395            self.3.encode(encoder, offset + 12, depth)?;
396            Ok(())
397        }
398    }
399
400    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Rgbc {
401        #[inline(always)]
402        fn new_empty() -> Self {
403            Self {
404                red_intensity: fidl::new_empty!(f32, D),
405                green_intensity: fidl::new_empty!(f32, D),
406                blue_intensity: fidl::new_empty!(f32, D),
407                clear_intensity: fidl::new_empty!(f32, D),
408            }
409        }
410
411        #[inline]
412        unsafe fn decode(
413            &mut self,
414            decoder: &mut fidl::encoding::Decoder<'_, D>,
415            offset: usize,
416            _depth: fidl::encoding::Depth,
417        ) -> fidl::Result<()> {
418            decoder.debug_check_bounds::<Self>(offset);
419            // Verify that padding bytes are zero.
420            fidl::decode!(f32, D, &mut self.red_intensity, decoder, offset + 0, _depth)?;
421            fidl::decode!(f32, D, &mut self.green_intensity, decoder, offset + 4, _depth)?;
422            fidl::decode!(f32, D, &mut self.blue_intensity, decoder, offset + 8, _depth)?;
423            fidl::decode!(f32, D, &mut self.clear_intensity, decoder, offset + 12, _depth)?;
424            Ok(())
425        }
426    }
427
428    impl fidl::encoding::ValueTypeMarker for SensorWatchResponse {
429        type Borrowed<'a> = &'a Self;
430        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
431            value
432        }
433    }
434
435    unsafe impl fidl::encoding::TypeMarker for SensorWatchResponse {
436        type Owned = Self;
437
438        #[inline(always)]
439        fn inline_align(_context: fidl::encoding::Context) -> usize {
440            8
441        }
442
443        #[inline(always)]
444        fn inline_size(_context: fidl::encoding::Context) -> usize {
445            16
446        }
447    }
448
449    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SensorWatchResponse, D>
450        for &SensorWatchResponse
451    {
452        #[inline]
453        unsafe fn encode(
454            self,
455            encoder: &mut fidl::encoding::Encoder<'_, D>,
456            offset: usize,
457            _depth: fidl::encoding::Depth,
458        ) -> fidl::Result<()> {
459            encoder.debug_check_bounds::<SensorWatchResponse>(offset);
460            // Delegate to tuple encoding.
461            fidl::encoding::Encode::<SensorWatchResponse, D>::encode(
462                (<LightSensorData as fidl::encoding::ValueTypeMarker>::borrow(&self.data),),
463                encoder,
464                offset,
465                _depth,
466            )
467        }
468    }
469    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<LightSensorData, D>>
470        fidl::encoding::Encode<SensorWatchResponse, D> for (T0,)
471    {
472        #[inline]
473        unsafe fn encode(
474            self,
475            encoder: &mut fidl::encoding::Encoder<'_, D>,
476            offset: usize,
477            depth: fidl::encoding::Depth,
478        ) -> fidl::Result<()> {
479            encoder.debug_check_bounds::<SensorWatchResponse>(offset);
480            // Zero out padding regions. There's no need to apply masks
481            // because the unmasked parts will be overwritten by fields.
482            // Write the fields.
483            self.0.encode(encoder, offset + 0, depth)?;
484            Ok(())
485        }
486    }
487
488    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SensorWatchResponse {
489        #[inline(always)]
490        fn new_empty() -> Self {
491            Self { data: fidl::new_empty!(LightSensorData, D) }
492        }
493
494        #[inline]
495        unsafe fn decode(
496            &mut self,
497            decoder: &mut fidl::encoding::Decoder<'_, D>,
498            offset: usize,
499            _depth: fidl::encoding::Depth,
500        ) -> fidl::Result<()> {
501            decoder.debug_check_bounds::<Self>(offset);
502            // Verify that padding bytes are zero.
503            fidl::decode!(LightSensorData, D, &mut self.data, decoder, offset + 0, _depth)?;
504            Ok(())
505        }
506    }
507
508    impl LightSensorData {
509        #[inline(always)]
510        fn max_ordinal_present(&self) -> u64 {
511            if let Some(_) = self.is_calibrated {
512                return 5;
513            }
514            if let Some(_) = self.si_rgbc {
515                return 4;
516            }
517            if let Some(_) = self.correlated_color_temperature {
518                return 3;
519            }
520            if let Some(_) = self.calculated_lux {
521                return 2;
522            }
523            if let Some(_) = self.rgbc {
524                return 1;
525            }
526            0
527        }
528    }
529
530    impl fidl::encoding::ValueTypeMarker for LightSensorData {
531        type Borrowed<'a> = &'a Self;
532        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
533            value
534        }
535    }
536
537    unsafe impl fidl::encoding::TypeMarker for LightSensorData {
538        type Owned = Self;
539
540        #[inline(always)]
541        fn inline_align(_context: fidl::encoding::Context) -> usize {
542            8
543        }
544
545        #[inline(always)]
546        fn inline_size(_context: fidl::encoding::Context) -> usize {
547            16
548        }
549    }
550
551    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<LightSensorData, D>
552        for &LightSensorData
553    {
554        unsafe fn encode(
555            self,
556            encoder: &mut fidl::encoding::Encoder<'_, D>,
557            offset: usize,
558            mut depth: fidl::encoding::Depth,
559        ) -> fidl::Result<()> {
560            encoder.debug_check_bounds::<LightSensorData>(offset);
561            // Vector header
562            let max_ordinal: u64 = self.max_ordinal_present();
563            encoder.write_num(max_ordinal, offset);
564            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
565            // Calling encoder.out_of_line_offset(0) is not allowed.
566            if max_ordinal == 0 {
567                return Ok(());
568            }
569            depth.increment()?;
570            let envelope_size = 8;
571            let bytes_len = max_ordinal as usize * envelope_size;
572            #[allow(unused_variables)]
573            let offset = encoder.out_of_line_offset(bytes_len);
574            let mut _prev_end_offset: usize = 0;
575            if 1 > max_ordinal {
576                return Ok(());
577            }
578
579            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
580            // are envelope_size bytes.
581            let cur_offset: usize = (1 - 1) * envelope_size;
582
583            // Zero reserved fields.
584            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
585
586            // Safety:
587            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
588            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
589            //   envelope_size bytes, there is always sufficient room.
590            fidl::encoding::encode_in_envelope_optional::<Rgbc, D>(
591                self.rgbc.as_ref().map(<Rgbc as fidl::encoding::ValueTypeMarker>::borrow),
592                encoder,
593                offset + cur_offset,
594                depth,
595            )?;
596
597            _prev_end_offset = cur_offset + envelope_size;
598            if 2 > max_ordinal {
599                return Ok(());
600            }
601
602            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
603            // are envelope_size bytes.
604            let cur_offset: usize = (2 - 1) * envelope_size;
605
606            // Zero reserved fields.
607            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
608
609            // Safety:
610            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
611            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
612            //   envelope_size bytes, there is always sufficient room.
613            fidl::encoding::encode_in_envelope_optional::<f32, D>(
614                self.calculated_lux.as_ref().map(<f32 as fidl::encoding::ValueTypeMarker>::borrow),
615                encoder,
616                offset + cur_offset,
617                depth,
618            )?;
619
620            _prev_end_offset = cur_offset + envelope_size;
621            if 3 > max_ordinal {
622                return Ok(());
623            }
624
625            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
626            // are envelope_size bytes.
627            let cur_offset: usize = (3 - 1) * envelope_size;
628
629            // Zero reserved fields.
630            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
631
632            // Safety:
633            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
634            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
635            //   envelope_size bytes, there is always sufficient room.
636            fidl::encoding::encode_in_envelope_optional::<f32, D>(
637                self.correlated_color_temperature
638                    .as_ref()
639                    .map(<f32 as fidl::encoding::ValueTypeMarker>::borrow),
640                encoder,
641                offset + cur_offset,
642                depth,
643            )?;
644
645            _prev_end_offset = cur_offset + envelope_size;
646            if 4 > max_ordinal {
647                return Ok(());
648            }
649
650            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
651            // are envelope_size bytes.
652            let cur_offset: usize = (4 - 1) * envelope_size;
653
654            // Zero reserved fields.
655            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
656
657            // Safety:
658            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
659            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
660            //   envelope_size bytes, there is always sufficient room.
661            fidl::encoding::encode_in_envelope_optional::<Rgbc, D>(
662                self.si_rgbc.as_ref().map(<Rgbc as fidl::encoding::ValueTypeMarker>::borrow),
663                encoder,
664                offset + cur_offset,
665                depth,
666            )?;
667
668            _prev_end_offset = cur_offset + envelope_size;
669            if 5 > max_ordinal {
670                return Ok(());
671            }
672
673            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
674            // are envelope_size bytes.
675            let cur_offset: usize = (5 - 1) * envelope_size;
676
677            // Zero reserved fields.
678            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
679
680            // Safety:
681            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
682            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
683            //   envelope_size bytes, there is always sufficient room.
684            fidl::encoding::encode_in_envelope_optional::<bool, D>(
685                self.is_calibrated.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
686                encoder,
687                offset + cur_offset,
688                depth,
689            )?;
690
691            _prev_end_offset = cur_offset + envelope_size;
692
693            Ok(())
694        }
695    }
696
697    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for LightSensorData {
698        #[inline(always)]
699        fn new_empty() -> Self {
700            Self::default()
701        }
702
703        unsafe fn decode(
704            &mut self,
705            decoder: &mut fidl::encoding::Decoder<'_, D>,
706            offset: usize,
707            mut depth: fidl::encoding::Depth,
708        ) -> fidl::Result<()> {
709            decoder.debug_check_bounds::<Self>(offset);
710            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
711                None => return Err(fidl::Error::NotNullable),
712                Some(len) => len,
713            };
714            // Calling decoder.out_of_line_offset(0) is not allowed.
715            if len == 0 {
716                return Ok(());
717            };
718            depth.increment()?;
719            let envelope_size = 8;
720            let bytes_len = len * envelope_size;
721            let offset = decoder.out_of_line_offset(bytes_len)?;
722            // Decode the envelope for each type.
723            let mut _next_ordinal_to_read = 0;
724            let mut next_offset = offset;
725            let end_offset = offset + bytes_len;
726            _next_ordinal_to_read += 1;
727            if next_offset >= end_offset {
728                return Ok(());
729            }
730
731            // Decode unknown envelopes for gaps in ordinals.
732            while _next_ordinal_to_read < 1 {
733                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
734                _next_ordinal_to_read += 1;
735                next_offset += envelope_size;
736            }
737
738            let next_out_of_line = decoder.next_out_of_line();
739            let handles_before = decoder.remaining_handles();
740            if let Some((inlined, num_bytes, num_handles)) =
741                fidl::encoding::decode_envelope_header(decoder, next_offset)?
742            {
743                let member_inline_size =
744                    <Rgbc as fidl::encoding::TypeMarker>::inline_size(decoder.context);
745                if inlined != (member_inline_size <= 4) {
746                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
747                }
748                let inner_offset;
749                let mut inner_depth = depth.clone();
750                if inlined {
751                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
752                    inner_offset = next_offset;
753                } else {
754                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
755                    inner_depth.increment()?;
756                }
757                let val_ref = self.rgbc.get_or_insert_with(|| fidl::new_empty!(Rgbc, D));
758                fidl::decode!(Rgbc, D, val_ref, decoder, inner_offset, inner_depth)?;
759                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
760                {
761                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
762                }
763                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
764                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
765                }
766            }
767
768            next_offset += envelope_size;
769            _next_ordinal_to_read += 1;
770            if next_offset >= end_offset {
771                return Ok(());
772            }
773
774            // Decode unknown envelopes for gaps in ordinals.
775            while _next_ordinal_to_read < 2 {
776                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
777                _next_ordinal_to_read += 1;
778                next_offset += envelope_size;
779            }
780
781            let next_out_of_line = decoder.next_out_of_line();
782            let handles_before = decoder.remaining_handles();
783            if let Some((inlined, num_bytes, num_handles)) =
784                fidl::encoding::decode_envelope_header(decoder, next_offset)?
785            {
786                let member_inline_size =
787                    <f32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
788                if inlined != (member_inline_size <= 4) {
789                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
790                }
791                let inner_offset;
792                let mut inner_depth = depth.clone();
793                if inlined {
794                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
795                    inner_offset = next_offset;
796                } else {
797                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
798                    inner_depth.increment()?;
799                }
800                let val_ref = self.calculated_lux.get_or_insert_with(|| fidl::new_empty!(f32, D));
801                fidl::decode!(f32, D, val_ref, decoder, inner_offset, inner_depth)?;
802                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
803                {
804                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
805                }
806                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
807                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
808                }
809            }
810
811            next_offset += envelope_size;
812            _next_ordinal_to_read += 1;
813            if next_offset >= end_offset {
814                return Ok(());
815            }
816
817            // Decode unknown envelopes for gaps in ordinals.
818            while _next_ordinal_to_read < 3 {
819                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
820                _next_ordinal_to_read += 1;
821                next_offset += envelope_size;
822            }
823
824            let next_out_of_line = decoder.next_out_of_line();
825            let handles_before = decoder.remaining_handles();
826            if let Some((inlined, num_bytes, num_handles)) =
827                fidl::encoding::decode_envelope_header(decoder, next_offset)?
828            {
829                let member_inline_size =
830                    <f32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
831                if inlined != (member_inline_size <= 4) {
832                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
833                }
834                let inner_offset;
835                let mut inner_depth = depth.clone();
836                if inlined {
837                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
838                    inner_offset = next_offset;
839                } else {
840                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
841                    inner_depth.increment()?;
842                }
843                let val_ref = self
844                    .correlated_color_temperature
845                    .get_or_insert_with(|| fidl::new_empty!(f32, D));
846                fidl::decode!(f32, D, val_ref, decoder, inner_offset, inner_depth)?;
847                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
848                {
849                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
850                }
851                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
852                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
853                }
854            }
855
856            next_offset += envelope_size;
857            _next_ordinal_to_read += 1;
858            if next_offset >= end_offset {
859                return Ok(());
860            }
861
862            // Decode unknown envelopes for gaps in ordinals.
863            while _next_ordinal_to_read < 4 {
864                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
865                _next_ordinal_to_read += 1;
866                next_offset += envelope_size;
867            }
868
869            let next_out_of_line = decoder.next_out_of_line();
870            let handles_before = decoder.remaining_handles();
871            if let Some((inlined, num_bytes, num_handles)) =
872                fidl::encoding::decode_envelope_header(decoder, next_offset)?
873            {
874                let member_inline_size =
875                    <Rgbc as fidl::encoding::TypeMarker>::inline_size(decoder.context);
876                if inlined != (member_inline_size <= 4) {
877                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
878                }
879                let inner_offset;
880                let mut inner_depth = depth.clone();
881                if inlined {
882                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
883                    inner_offset = next_offset;
884                } else {
885                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
886                    inner_depth.increment()?;
887                }
888                let val_ref = self.si_rgbc.get_or_insert_with(|| fidl::new_empty!(Rgbc, D));
889                fidl::decode!(Rgbc, D, val_ref, decoder, inner_offset, inner_depth)?;
890                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
891                {
892                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
893                }
894                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
895                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
896                }
897            }
898
899            next_offset += envelope_size;
900            _next_ordinal_to_read += 1;
901            if next_offset >= end_offset {
902                return Ok(());
903            }
904
905            // Decode unknown envelopes for gaps in ordinals.
906            while _next_ordinal_to_read < 5 {
907                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
908                _next_ordinal_to_read += 1;
909                next_offset += envelope_size;
910            }
911
912            let next_out_of_line = decoder.next_out_of_line();
913            let handles_before = decoder.remaining_handles();
914            if let Some((inlined, num_bytes, num_handles)) =
915                fidl::encoding::decode_envelope_header(decoder, next_offset)?
916            {
917                let member_inline_size =
918                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
919                if inlined != (member_inline_size <= 4) {
920                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
921                }
922                let inner_offset;
923                let mut inner_depth = depth.clone();
924                if inlined {
925                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
926                    inner_offset = next_offset;
927                } else {
928                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
929                    inner_depth.increment()?;
930                }
931                let val_ref = self.is_calibrated.get_or_insert_with(|| fidl::new_empty!(bool, D));
932                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
933                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
934                {
935                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
936                }
937                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
938                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
939                }
940            }
941
942            next_offset += envelope_size;
943
944            // Decode the remaining unknown envelopes.
945            while next_offset < end_offset {
946                _next_ordinal_to_read += 1;
947                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
948                next_offset += envelope_size;
949            }
950
951            Ok(())
952        }
953    }
954}