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