rustyfit 0.10.0

The #![no_std] Rust implementation of The Flexible and Interoperable Data Transfer (FIT) Protocol for decoding and encoding Garmin FIT files, supporting FIT Protocol V2.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
// Code generated by fitgen/main.go. DO NOT EDIT.

// Copyright 2025 The RustyFIT Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

use crate::profile::typedef::{self, FitBaseType};
use crate::proto::*;
use alloc::vec::Vec;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize, Serializer, ser::SerializeStruct};

/// Aviation Attitude message.
#[cfg_attr(feature = "serde", derive(Deserialize), serde(from = "De"))]
#[derive(Debug, Clone)]
pub struct AviationAttitude {
    /// Units: s; Timestamp message was output
    pub timestamp: typedef::DateTime,
    /// Units: ms; Fractional part of timestamp, added to timestamp
    pub timestamp_ms: u16,
    /// Units: ms; System time associated with sample expressed in ms.
    pub system_time: Vec<u32>,
    /// Scale: 10430.38; Units: radians; Range -PI/2 to +PI/2
    pub pitch: Vec<i16>,
    /// Scale: 10430.38; Units: radians; Range -PI to +PI
    pub roll: Vec<i16>,
    /// Scale: 100; Units: m/s^2; Range -78.4 to +78.4 (-8 Gs to 8 Gs)
    pub accel_lateral: Vec<i16>,
    /// Scale: 100; Units: m/s^2; Range -78.4 to +78.4 (-8 Gs to 8 Gs)
    pub accel_normal: Vec<i16>,
    /// Scale: 1024; Units: radians/second; Range -8.727 to +8.727 (-500 degs/sec to +500 degs/sec)
    pub turn_rate: Vec<i16>,
    pub stage: Vec<typedef::AttitudeStage>,
    /// Units: %; The percent complete of the current attitude stage. Set to 0 for attitude stages 0, 1 and 2 and to 100 for attitude stage 3 by AHRS modules that do not support it. Range - 100
    pub attitude_stage_complete: Vec<u8>,
    /// Scale: 10430.38; Units: radians; Track Angle/Heading Range 0 - 2pi
    pub track: Vec<u16>,
    pub validity: Vec<typedef::AttitudeValidity>,
    /// unknown_fields are fields that are exist but they are not defined in Profile.xlsx
    pub unknown_fields: Vec<Field>,
    /// developer_fields are custom data fields (Added since protocol version 2.0)
    pub developer_fields: Vec<DeveloperField>,
}

impl AviationAttitude {
    /// Value's type: `u32`; FitBaseType::UINT32; ProfileType::DateTime; Units: `s`
    pub const TIMESTAMP: u8 = 253;
    /// Value's type: `u16`; FitBaseType::UINT16; ProfileType::Uint16; Units: `ms`
    pub const TIMESTAMP_MS: u8 = 0;
    /// Value's type: `Vec<u32>`; FitBaseType::UINT32; ProfileType::Uint32; Units: `ms`
    pub const SYSTEM_TIME: u8 = 1;
    /// Value's type: `Vec<i16>`; FitBaseType::SINT16; ProfileType::Sint16; Scale: `10430.38`; Units: `radians`
    pub const PITCH: u8 = 2;
    /// Value's type: `Vec<i16>`; FitBaseType::SINT16; ProfileType::Sint16; Scale: `10430.38`; Units: `radians`
    pub const ROLL: u8 = 3;
    /// Value's type: `Vec<i16>`; FitBaseType::SINT16; ProfileType::Sint16; Scale: `100`; Units: `m/s^2`
    pub const ACCEL_LATERAL: u8 = 4;
    /// Value's type: `Vec<i16>`; FitBaseType::SINT16; ProfileType::Sint16; Scale: `100`; Units: `m/s^2`
    pub const ACCEL_NORMAL: u8 = 5;
    /// Value's type: `Vec<i16>`; FitBaseType::SINT16; ProfileType::Sint16; Scale: `1024`; Units: `radians/second`
    pub const TURN_RATE: u8 = 6;
    /// Value's type: `Vec<u8>`; FitBaseType::ENUM; ProfileType::AttitudeStage
    pub const STAGE: u8 = 7;
    /// Value's type: `Vec<u8>`; FitBaseType::UINT8; ProfileType::Uint8; Units: `%`
    pub const ATTITUDE_STAGE_COMPLETE: u8 = 8;
    /// Value's type: `Vec<u16>`; FitBaseType::UINT16; ProfileType::Uint16; Scale: `10430.38`; Units: `radians`
    pub const TRACK: u8 = 9;
    /// Value's type: `Vec<u16>`; FitBaseType::UINT16; ProfileType::AttitudeValidity
    pub const VALIDITY: u8 = 10;

    /// Create new AviationAttitude with all fields being set to its corresponding invalid value.
    pub const fn new() -> Self {
        Self {
            timestamp: typedef::DateTime(u32::MAX),
            timestamp_ms: u16::MAX,
            system_time: Vec::new(),
            pitch: Vec::new(),
            roll: Vec::new(),
            accel_lateral: Vec::new(),
            accel_normal: Vec::new(),
            turn_rate: Vec::new(),
            stage: Vec::new(),
            attitude_stage_complete: Vec::new(),
            track: Vec::new(),
            validity: Vec::new(),
            unknown_fields: Vec::new(),
            developer_fields: Vec::new(),
        }
    }

    /// Returns `pitch` in its scaled value. It returns `None` when value is invalid.
    ///
    /// Units: radians
    pub fn pitch_scaled(&self) -> Option<Vec<f64>> {
        if self.pitch.is_empty() {
            return None;
        }
        let mut v = Vec::with_capacity(self.pitch.len());
        for &x in &self.pitch {
            v.push(x as f64 / 10430.38 - 0.0)
        }
        Some(v)
    }

    /// Set `pitch` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_pitch_scaled(&mut self, v: &[f64]) -> &mut Self {
        self.pitch = Vec::with_capacity(v.len());
        if v.is_empty() {
            return self;
        }
        for &x in v {
            let unscaled = (x + 0.0) * 10430.38;
            if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64 {
                self.pitch.push(i16::MAX);
                continue;
            }
            self.pitch.push(unscaled as i16);
        }
        self
    }

    /// Returns `roll` in its scaled value. It returns `None` when value is invalid.
    ///
    /// Units: radians
    pub fn roll_scaled(&self) -> Option<Vec<f64>> {
        if self.roll.is_empty() {
            return None;
        }
        let mut v = Vec::with_capacity(self.roll.len());
        for &x in &self.roll {
            v.push(x as f64 / 10430.38 - 0.0)
        }
        Some(v)
    }

    /// Set `roll` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_roll_scaled(&mut self, v: &[f64]) -> &mut Self {
        self.roll = Vec::with_capacity(v.len());
        if v.is_empty() {
            return self;
        }
        for &x in v {
            let unscaled = (x + 0.0) * 10430.38;
            if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64 {
                self.roll.push(i16::MAX);
                continue;
            }
            self.roll.push(unscaled as i16);
        }
        self
    }

    /// Returns `accel_lateral` in its scaled value. It returns `None` when value is invalid.
    ///
    /// Units: m/s^2
    pub fn accel_lateral_scaled(&self) -> Option<Vec<f64>> {
        if self.accel_lateral.is_empty() {
            return None;
        }
        let mut v = Vec::with_capacity(self.accel_lateral.len());
        for &x in &self.accel_lateral {
            v.push(x as f64 / 100.0 - 0.0)
        }
        Some(v)
    }

    /// Set `accel_lateral` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_accel_lateral_scaled(&mut self, v: &[f64]) -> &mut Self {
        self.accel_lateral = Vec::with_capacity(v.len());
        if v.is_empty() {
            return self;
        }
        for &x in v {
            let unscaled = (x + 0.0) * 100.0;
            if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64 {
                self.accel_lateral.push(i16::MAX);
                continue;
            }
            self.accel_lateral.push(unscaled as i16);
        }
        self
    }

    /// Returns `accel_normal` in its scaled value. It returns `None` when value is invalid.
    ///
    /// Units: m/s^2
    pub fn accel_normal_scaled(&self) -> Option<Vec<f64>> {
        if self.accel_normal.is_empty() {
            return None;
        }
        let mut v = Vec::with_capacity(self.accel_normal.len());
        for &x in &self.accel_normal {
            v.push(x as f64 / 100.0 - 0.0)
        }
        Some(v)
    }

    /// Set `accel_normal` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_accel_normal_scaled(&mut self, v: &[f64]) -> &mut Self {
        self.accel_normal = Vec::with_capacity(v.len());
        if v.is_empty() {
            return self;
        }
        for &x in v {
            let unscaled = (x + 0.0) * 100.0;
            if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64 {
                self.accel_normal.push(i16::MAX);
                continue;
            }
            self.accel_normal.push(unscaled as i16);
        }
        self
    }

    /// Returns `turn_rate` in its scaled value. It returns `None` when value is invalid.
    ///
    /// Units: radians/second
    pub fn turn_rate_scaled(&self) -> Option<Vec<f64>> {
        if self.turn_rate.is_empty() {
            return None;
        }
        let mut v = Vec::with_capacity(self.turn_rate.len());
        for &x in &self.turn_rate {
            v.push(x as f64 / 1024.0 - 0.0)
        }
        Some(v)
    }

    /// Set `turn_rate` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_turn_rate_scaled(&mut self, v: &[f64]) -> &mut Self {
        self.turn_rate = Vec::with_capacity(v.len());
        if v.is_empty() {
            return self;
        }
        for &x in v {
            let unscaled = (x + 0.0) * 1024.0;
            if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64 {
                self.turn_rate.push(i16::MAX);
                continue;
            }
            self.turn_rate.push(unscaled as i16);
        }
        self
    }

    /// Returns `track` in its scaled value. It returns `None` when value is invalid.
    ///
    /// Units: radians
    pub fn track_scaled(&self) -> Option<Vec<f64>> {
        if self.track.is_empty() {
            return None;
        }
        let mut v = Vec::with_capacity(self.track.len());
        for &x in &self.track {
            v.push(x as f64 / 10430.38 - 0.0)
        }
        Some(v)
    }

    /// Set `track` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_track_scaled(&mut self, v: &[f64]) -> &mut Self {
        self.track = Vec::with_capacity(v.len());
        if v.is_empty() {
            return self;
        }
        for &x in v {
            let unscaled = (x + 0.0) * 10430.38;
            if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u16::MAX as f64 {
                self.track.push(u16::MAX);
                continue;
            }
            self.track.push(unscaled as u16);
        }
        self
    }

    fn count_valid_fields(&self) -> usize {
        (self.timestamp.0 != u32::MAX) as usize
            + (self.timestamp_ms != u16::MAX) as usize
            + (!self.system_time.is_empty()) as usize
            + (!self.pitch.is_empty()) as usize
            + (!self.roll.is_empty()) as usize
            + (!self.accel_lateral.is_empty()) as usize
            + (!self.accel_normal.is_empty()) as usize
            + (!self.turn_rate.is_empty()) as usize
            + (!self.stage.is_empty()) as usize
            + (!self.attitude_stage_complete.is_empty()) as usize
            + (!self.track.is_empty()) as usize
            + (!self.validity.is_empty()) as usize
    }
}

impl Default for AviationAttitude {
    fn default() -> Self {
        Self::new()
    }
}

impl From<&Message> for AviationAttitude {
    /// from creates new AviationAttitude struct based on given mesg.
    fn from(mesg: &Message) -> Self {
        const KNOWN_NUMS: [u64; 4] = [2047, 0, 0, 2305843009213693952];
        let mut n = 0u64;
        for field in &mesg.fields {
            n += (KNOWN_NUMS[field.num as usize >> 6] >> (field.num & 63)) & 1 ^ 1
        }

        let mut v = Self::new();
        v.unknown_fields = Vec::<Field>::with_capacity(n as usize);
        v.developer_fields = mesg.developer_fields.clone();

        for field in &mesg.fields {
            match field.num {
                253 => v.timestamp = typedef::DateTime(field.value.as_u32()),
                0 => v.timestamp_ms = field.value.as_u16(),
                1 => v.system_time = field.value.to_vec_u32(),
                2 => v.pitch = field.value.to_vec_i16(),
                3 => v.roll = field.value.to_vec_i16(),
                4 => v.accel_lateral = field.value.to_vec_i16(),
                5 => v.accel_normal = field.value.to_vec_i16(),
                6 => v.turn_rate = field.value.to_vec_i16(),
                7 => {
                    v.stage = match &field.value {
                        Value::VecUint8(v) => {
                            let mut vs = Vec::with_capacity(v.len());
                            vs.extend(v.iter().map(|&x| typedef::AttitudeStage(x)));
                            vs
                        }
                        _ => Vec::new(),
                    }
                }
                8 => v.attitude_stage_complete = field.value.to_vec_u8(),
                9 => v.track = field.value.to_vec_u16(),
                10 => {
                    v.validity = match &field.value {
                        Value::VecUint16(v) => {
                            let mut vs = Vec::with_capacity(v.len());
                            vs.extend(v.iter().map(|&x| typedef::AttitudeValidity(x)));
                            vs
                        }
                        _ => Vec::new(),
                    }
                }
                _ => v.unknown_fields.push(field.clone()),
            };
        }

        v
    }
}

impl From<AviationAttitude> for Message {
    fn from(m: AviationAttitude) -> Self {
        let mut fields =
            Vec::<Field>::with_capacity(m.count_valid_fields() + m.unknown_fields.len());

        if m.timestamp.0 != u32::MAX {
            fields.push(Field {
                num: 253,
                base_type: FitBaseType::UINT32,
                value: Value::Uint32(m.timestamp.0),
                is_expanded: false,
            });
        };
        if m.timestamp_ms != u16::MAX {
            fields.push(Field {
                num: 0,
                base_type: FitBaseType::UINT16,
                value: Value::Uint16(m.timestamp_ms),
                is_expanded: false,
            });
        };
        if !m.system_time.is_empty() {
            fields.push(Field {
                num: 1,
                base_type: FitBaseType::UINT32,
                value: Value::VecUint32(m.system_time),
                is_expanded: false,
            });
        };
        if !m.pitch.is_empty() {
            fields.push(Field {
                num: 2,
                base_type: FitBaseType::SINT16,
                value: Value::VecInt16(m.pitch),
                is_expanded: false,
            });
        };
        if !m.roll.is_empty() {
            fields.push(Field {
                num: 3,
                base_type: FitBaseType::SINT16,
                value: Value::VecInt16(m.roll),
                is_expanded: false,
            });
        };
        if !m.accel_lateral.is_empty() {
            fields.push(Field {
                num: 4,
                base_type: FitBaseType::SINT16,
                value: Value::VecInt16(m.accel_lateral),
                is_expanded: false,
            });
        };
        if !m.accel_normal.is_empty() {
            fields.push(Field {
                num: 5,
                base_type: FitBaseType::SINT16,
                value: Value::VecInt16(m.accel_normal),
                is_expanded: false,
            });
        };
        if !m.turn_rate.is_empty() {
            fields.push(Field {
                num: 6,
                base_type: FitBaseType::SINT16,
                value: Value::VecInt16(m.turn_rate),
                is_expanded: false,
            });
        };
        if !m.stage.is_empty() {
            fields.push(Field {
                num: 7,
                base_type: FitBaseType::ENUM,
                value: Value::VecUint8({
                    let (ptr, len, capacity) = m.stage.into_raw_parts();
                    unsafe { Vec::from_raw_parts(ptr.cast::<u8>(), len, capacity) }
                }),
                is_expanded: false,
            });
        };
        if !m.attitude_stage_complete.is_empty() {
            fields.push(Field {
                num: 8,
                base_type: FitBaseType::UINT8,
                value: Value::VecUint8(m.attitude_stage_complete),
                is_expanded: false,
            });
        };
        if !m.track.is_empty() {
            fields.push(Field {
                num: 9,
                base_type: FitBaseType::UINT16,
                value: Value::VecUint16(m.track),
                is_expanded: false,
            });
        };
        if !m.validity.is_empty() {
            fields.push(Field {
                num: 10,
                base_type: FitBaseType::UINT16,
                value: Value::VecUint16({
                    let (ptr, len, capacity) = m.validity.into_raw_parts();
                    unsafe { Vec::from_raw_parts(ptr.cast::<u16>(), len, capacity) }
                }),
                is_expanded: false,
            });
        };

        fields.extend_from_slice(&m.unknown_fields);

        Self {
            header: 0,
            num: typedef::MesgNum::AVIATION_ATTITUDE,
            fields,
            developer_fields: m.developer_fields,
        }
    }
}

#[cfg(feature = "serde")]
impl Serialize for AviationAttitude {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let n = self.count_valid_fields() + 2;
        let mut state = serializer.serialize_struct("AviationAttitude", n)?;
        if let Some(v) = self.timestamp.unix_timestamp() {
            state.serialize_field("timestamp", &v)?;
        }
        if self.timestamp_ms != u16::MAX {
            state.serialize_field("timestamp_ms", &self.timestamp_ms)?;
        }
        if !self.system_time.is_empty() {
            state.serialize_field("system_time", &self.system_time)?;
        }
        if let Some(v) = self.pitch_scaled() {
            state.serialize_field("pitch", &v)?;
        }
        if let Some(v) = self.roll_scaled() {
            state.serialize_field("roll", &v)?;
        }
        if let Some(v) = self.accel_lateral_scaled() {
            state.serialize_field("accel_lateral", &v)?;
        }
        if let Some(v) = self.accel_normal_scaled() {
            state.serialize_field("accel_normal", &v)?;
        }
        if let Some(v) = self.turn_rate_scaled() {
            state.serialize_field("turn_rate", &v)?;
        }
        if !self.stage.is_empty() {
            state.serialize_field("stage", &self.stage)?;
        }
        if !self.attitude_stage_complete.is_empty() {
            state.serialize_field("attitude_stage_complete", &self.attitude_stage_complete)?;
        }
        if let Some(v) = self.track_scaled() {
            state.serialize_field("track", &v)?;
        }
        if !self.validity.is_empty() {
            state.serialize_field("validity", &self.validity)?;
        }
        if !self.unknown_fields.is_empty() {
            state.serialize_field("unknown_fields", &self.unknown_fields)?;
        }
        if !self.developer_fields.is_empty() {
            state.serialize_field("developer_fields", &self.developer_fields)?;
        }
        state.end()
    }
}

#[cfg(feature = "serde")]
#[cfg_attr(feature = "serde", derive(Deserialize), serde(default))]
struct De {
    timestamp: Option<i64>,
    timestamp_ms: u16,
    system_time: Vec<u32>,
    pitch: Vec<f64>,
    roll: Vec<f64>,
    accel_lateral: Vec<f64>,
    accel_normal: Vec<f64>,
    turn_rate: Vec<f64>,
    stage: Vec<typedef::AttitudeStage>,
    attitude_stage_complete: Vec<u8>,
    track: Vec<f64>,
    validity: Vec<typedef::AttitudeValidity>,
    unknown_fields: Vec<Field>,
    developer_fields: Vec<DeveloperField>,
}

#[cfg(feature = "serde")]
impl From<De> for AviationAttitude {
    fn from(m: De) -> Self {
        Self {
            timestamp: m.timestamp.map_or_else(
                || typedef::DateTime(u32::MAX),
                typedef::DateTime::from_unix_timestamp,
            ),
            timestamp_ms: m.timestamp_ms,
            system_time: m.system_time,
            pitch: {
                if m.pitch.is_empty() {
                    Vec::new()
                } else {
                    let mut vals = Vec::with_capacity(m.pitch.len());
                    for &x in m.pitch.iter() {
                        let unscaled = (x + 0.0) * 10430.38;
                        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64
                        {
                            vals.push(i16::MAX);
                            continue;
                        }
                        vals.push(unscaled as i16);
                    }
                    vals
                }
            },
            roll: {
                if m.roll.is_empty() {
                    Vec::new()
                } else {
                    let mut vals = Vec::with_capacity(m.roll.len());
                    for &x in m.roll.iter() {
                        let unscaled = (x + 0.0) * 10430.38;
                        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64
                        {
                            vals.push(i16::MAX);
                            continue;
                        }
                        vals.push(unscaled as i16);
                    }
                    vals
                }
            },
            accel_lateral: {
                if m.accel_lateral.is_empty() {
                    Vec::new()
                } else {
                    let mut vals = Vec::with_capacity(m.accel_lateral.len());
                    for &x in m.accel_lateral.iter() {
                        let unscaled = (x + 0.0) * 100.0;
                        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64
                        {
                            vals.push(i16::MAX);
                            continue;
                        }
                        vals.push(unscaled as i16);
                    }
                    vals
                }
            },
            accel_normal: {
                if m.accel_normal.is_empty() {
                    Vec::new()
                } else {
                    let mut vals = Vec::with_capacity(m.accel_normal.len());
                    for &x in m.accel_normal.iter() {
                        let unscaled = (x + 0.0) * 100.0;
                        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64
                        {
                            vals.push(i16::MAX);
                            continue;
                        }
                        vals.push(unscaled as i16);
                    }
                    vals
                }
            },
            turn_rate: {
                if m.turn_rate.is_empty() {
                    Vec::new()
                } else {
                    let mut vals = Vec::with_capacity(m.turn_rate.len());
                    for &x in m.turn_rate.iter() {
                        let unscaled = (x + 0.0) * 1024.0;
                        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > i16::MAX as f64
                        {
                            vals.push(i16::MAX);
                            continue;
                        }
                        vals.push(unscaled as i16);
                    }
                    vals
                }
            },
            stage: m.stage,
            attitude_stage_complete: m.attitude_stage_complete,
            track: {
                if m.track.is_empty() {
                    Vec::new()
                } else {
                    let mut vals = Vec::with_capacity(m.track.len());
                    for &x in m.track.iter() {
                        let unscaled = (x + 0.0) * 10430.38;
                        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u16::MAX as f64
                        {
                            vals.push(u16::MAX);
                            continue;
                        }
                        vals.push(unscaled as u16);
                    }
                    vals
                }
            },
            validity: m.validity,
            unknown_fields: m.unknown_fields,
            developer_fields: m.developer_fields,
        }
    }
}

#[cfg(feature = "serde")]
impl Default for De {
    fn default() -> Self {
        Self {
            timestamp: None,
            timestamp_ms: u16::MAX,
            system_time: Vec::new(),
            pitch: Vec::new(),
            roll: Vec::new(),
            accel_lateral: Vec::new(),
            accel_normal: Vec::new(),
            turn_rate: Vec::new(),
            stage: Vec::new(),
            attitude_stage_complete: Vec::new(),
            track: Vec::new(),
            validity: Vec::new(),
            unknown_fields: Vec::new(),
            developer_fields: Vec::new(),
        }
    }
}