rustyfit 0.4.1

This project hosts the Rust implementation for The Flexible and Interoperable Data Transfer (FIT) Protocol
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
// 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.

#![allow(unused, clippy::comparison_to_empty, clippy::manual_range_patterns)]

use crate::profile::{ProfileType, typedef};
use crate::proto::*;

#[derive(Debug, Clone)]
/// DiveSettings is a DiveSettings message.
pub struct DiveSettings {
    pub timestamp: typedef::DateTime,
    pub message_index: typedef::MessageIndex,
    pub name: String,
    pub model: typedef::TissueModelType,
    /// Units: percent
    pub gf_low: u8,
    /// Units: percent
    pub gf_high: u8,
    pub water_type: typedef::WaterType,
    /// Units: kg/m^3; Fresh water is usually 1000; salt water is usually 1025
    pub water_density: f32,
    /// Scale: 100; Units: percent; Typically 1.40
    pub po2_warn: u8,
    /// Scale: 100; Units: percent; Typically 1.60
    pub po2_critical: u8,
    /// Scale: 100; Units: percent
    pub po2_deco: u8,
    pub safety_stop_enabled: typedef::Bool,
    pub bottom_depth: f32,
    pub bottom_time: u32,
    pub apnea_countdown_enabled: typedef::Bool,
    pub apnea_countdown_time: u32,
    pub backlight_mode: typedef::DiveBacklightMode,
    pub backlight_brightness: u8,
    pub backlight_timeout: typedef::BacklightTimeout,
    /// Units: s; Time between surfacing and ending the activity
    pub repeat_dive_interval: u16,
    /// Units: s; Time at safety stop (if enabled)
    pub safety_stop_time: u16,
    pub heart_rate_source_type: typedef::SourceType,
    pub heart_rate_source: u8,
    /// Index of travel dive_gas message
    pub travel_gas: typedef::MessageIndex,
    /// If low PO2 should be switched to automatically
    pub ccr_low_setpoint_switch_mode: typedef::CcrSetpointSwitchMode,
    /// Scale: 100; Units: percent; Target PO2 when using low setpoint
    pub ccr_low_setpoint: u8,
    /// Scale: 1000; Units: m; Depth to switch to low setpoint in automatic mode
    pub ccr_low_setpoint_depth: u32,
    /// If high PO2 should be switched to automatically
    pub ccr_high_setpoint_switch_mode: typedef::CcrSetpointSwitchMode,
    /// Scale: 100; Units: percent; Target PO2 when using high setpoint
    pub ccr_high_setpoint: u8,
    /// Scale: 1000; Units: m; Depth to switch to high setpoint in automatic mode
    pub ccr_high_setpoint_depth: u32,
    /// Type of gas consumption rate to display. Some values are only valid if tank volume is known.
    pub gas_consumption_display: typedef::GasConsumptionRateType,
    /// Indicates whether the up key is enabled during dives
    pub up_key_enabled: typedef::Bool,
    /// Sounds and vibration enabled or disabled in-dive
    pub dive_sounds: typedef::Tone,
    /// Scale: 10; Usually 1.0/1.5/2.0 representing 3/4.5/6m or 10/15/20ft
    pub last_stop_multiple: u8,
    /// Indicates which guidelines to use for no-fly surface interval.
    pub no_fly_time_mode: typedef::NoFlyTimeMode,
    /// 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 DiveSettings {
    /// Value's type: `u32`
    pub const TIMESTAMP: u8 = 253;
    /// Value's type: `u16`
    pub const MESSAGE_INDEX: u8 = 254;
    /// Value's type: `String`
    pub const NAME: u8 = 0;
    /// Value's type: `u8`
    pub const MODEL: u8 = 1;
    /// Value's type: `u8`; Units: `percent`
    pub const GF_LOW: u8 = 2;
    /// Value's type: `u8`; Units: `percent`
    pub const GF_HIGH: u8 = 3;
    /// Value's type: `u8`
    pub const WATER_TYPE: u8 = 4;
    /// Value's type: `f32`; Units: `kg/m^3`
    pub const WATER_DENSITY: u8 = 5;
    /// Value's type: `u8`; Scale: `100`; Units: `percent`
    pub const PO2_WARN: u8 = 6;
    /// Value's type: `u8`; Scale: `100`; Units: `percent`
    pub const PO2_CRITICAL: u8 = 7;
    /// Value's type: `u8`; Scale: `100`; Units: `percent`
    pub const PO2_DECO: u8 = 8;
    /// Value's type: `u8`
    pub const SAFETY_STOP_ENABLED: u8 = 9;
    /// Value's type: `f32`
    pub const BOTTOM_DEPTH: u8 = 10;
    /// Value's type: `u32`
    pub const BOTTOM_TIME: u8 = 11;
    /// Value's type: `u8`
    pub const APNEA_COUNTDOWN_ENABLED: u8 = 12;
    /// Value's type: `u32`
    pub const APNEA_COUNTDOWN_TIME: u8 = 13;
    /// Value's type: `u8`
    pub const BACKLIGHT_MODE: u8 = 14;
    /// Value's type: `u8`
    pub const BACKLIGHT_BRIGHTNESS: u8 = 15;
    /// Value's type: `u8`
    pub const BACKLIGHT_TIMEOUT: u8 = 16;
    /// Value's type: `u16`; Units: `s`
    pub const REPEAT_DIVE_INTERVAL: u8 = 17;
    /// Value's type: `u16`; Units: `s`
    pub const SAFETY_STOP_TIME: u8 = 18;
    /// Value's type: `u8`
    pub const HEART_RATE_SOURCE_TYPE: u8 = 19;
    /// Value's type: `u8`
    pub const HEART_RATE_SOURCE: u8 = 20;
    /// Value's type: `u16`
    pub const TRAVEL_GAS: u8 = 21;
    /// Value's type: `u8`
    pub const CCR_LOW_SETPOINT_SWITCH_MODE: u8 = 22;
    /// Value's type: `u8`; Scale: `100`; Units: `percent`
    pub const CCR_LOW_SETPOINT: u8 = 23;
    /// Value's type: `u32`; Scale: `1000`; Units: `m`
    pub const CCR_LOW_SETPOINT_DEPTH: u8 = 24;
    /// Value's type: `u8`
    pub const CCR_HIGH_SETPOINT_SWITCH_MODE: u8 = 25;
    /// Value's type: `u8`; Scale: `100`; Units: `percent`
    pub const CCR_HIGH_SETPOINT: u8 = 26;
    /// Value's type: `u32`; Scale: `1000`; Units: `m`
    pub const CCR_HIGH_SETPOINT_DEPTH: u8 = 27;
    /// Value's type: `u8`
    pub const GAS_CONSUMPTION_DISPLAY: u8 = 29;
    /// Value's type: `u8`
    pub const UP_KEY_ENABLED: u8 = 30;
    /// Value's type: `u8`
    pub const DIVE_SOUNDS: u8 = 35;
    /// Value's type: `u8`; Scale: `10`
    pub const LAST_STOP_MULTIPLE: u8 = 36;
    /// Value's type: `u8`
    pub const NO_FLY_TIME_MODE: u8 = 37;

    /// Create new DiveSettings with all fields being set to its corresponding invalid value.
    pub const fn new() -> Self {
        Self {
            timestamp: typedef::DateTime(u32::MAX),
            message_index: typedef::MessageIndex(u16::MAX),
            name: String::new(),
            model: typedef::TissueModelType(u8::MAX),
            gf_low: u8::MAX,
            gf_high: u8::MAX,
            water_type: typedef::WaterType(u8::MAX),
            water_density: f32::MAX,
            po2_warn: u8::MAX,
            po2_critical: u8::MAX,
            po2_deco: u8::MAX,
            safety_stop_enabled: typedef::Bool(u8::MAX),
            bottom_depth: f32::MAX,
            bottom_time: u32::MAX,
            apnea_countdown_enabled: typedef::Bool(u8::MAX),
            apnea_countdown_time: u32::MAX,
            backlight_mode: typedef::DiveBacklightMode(u8::MAX),
            backlight_brightness: u8::MAX,
            backlight_timeout: typedef::BacklightTimeout(u8::MAX),
            repeat_dive_interval: u16::MAX,
            safety_stop_time: u16::MAX,
            heart_rate_source_type: typedef::SourceType(u8::MAX),
            heart_rate_source: u8::MAX,
            travel_gas: typedef::MessageIndex(u16::MAX),
            ccr_low_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(u8::MAX),
            ccr_low_setpoint: u8::MAX,
            ccr_low_setpoint_depth: u32::MAX,
            ccr_high_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(u8::MAX),
            ccr_high_setpoint: u8::MAX,
            ccr_high_setpoint_depth: u32::MAX,
            gas_consumption_display: typedef::GasConsumptionRateType(u8::MAX),
            up_key_enabled: typedef::Bool(u8::MAX),
            dive_sounds: typedef::Tone(u8::MAX),
            last_stop_multiple: u8::MAX,
            no_fly_time_mode: typedef::NoFlyTimeMode(u8::MAX),
            unknown_fields: Vec::new(),
            developer_fields: Vec::new(),
        }
    }

    /// Returns `po2_warn` in its scaled value. It returns invalid f64 when value is valid.
    pub fn po2_warn_scaled(&self) -> f64 {
        if self.po2_warn == u8::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.po2_warn as f64 / 100.0 - 0.0
    }

    /// Set `po2_warn` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_po2_warn_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 100.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
            self.po2_warn = u8::MAX;
            return self;
        }
        self.po2_warn = unscaled as u8;
        self
    }

    /// Returns `po2_critical` in its scaled value. It returns invalid f64 when value is valid.
    pub fn po2_critical_scaled(&self) -> f64 {
        if self.po2_critical == u8::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.po2_critical as f64 / 100.0 - 0.0
    }

    /// Set `po2_critical` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_po2_critical_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 100.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
            self.po2_critical = u8::MAX;
            return self;
        }
        self.po2_critical = unscaled as u8;
        self
    }

    /// Returns `po2_deco` in its scaled value. It returns invalid f64 when value is valid.
    pub fn po2_deco_scaled(&self) -> f64 {
        if self.po2_deco == u8::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.po2_deco as f64 / 100.0 - 0.0
    }

    /// Set `po2_deco` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_po2_deco_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 100.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
            self.po2_deco = u8::MAX;
            return self;
        }
        self.po2_deco = unscaled as u8;
        self
    }

    /// Returns `ccr_low_setpoint` in its scaled value. It returns invalid f64 when value is valid.
    pub fn ccr_low_setpoint_scaled(&self) -> f64 {
        if self.ccr_low_setpoint == u8::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.ccr_low_setpoint as f64 / 100.0 - 0.0
    }

    /// Set `ccr_low_setpoint` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_ccr_low_setpoint_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 100.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
            self.ccr_low_setpoint = u8::MAX;
            return self;
        }
        self.ccr_low_setpoint = unscaled as u8;
        self
    }

    /// Returns `ccr_low_setpoint_depth` in its scaled value. It returns invalid f64 when value is valid.
    pub fn ccr_low_setpoint_depth_scaled(&self) -> f64 {
        if self.ccr_low_setpoint_depth == u32::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.ccr_low_setpoint_depth as f64 / 1000.0 - 0.0
    }

    /// Set `ccr_low_setpoint_depth` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_ccr_low_setpoint_depth_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 1000.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u32::MAX as f64 {
            self.ccr_low_setpoint_depth = u32::MAX;
            return self;
        }
        self.ccr_low_setpoint_depth = unscaled as u32;
        self
    }

    /// Returns `ccr_high_setpoint` in its scaled value. It returns invalid f64 when value is valid.
    pub fn ccr_high_setpoint_scaled(&self) -> f64 {
        if self.ccr_high_setpoint == u8::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.ccr_high_setpoint as f64 / 100.0 - 0.0
    }

    /// Set `ccr_high_setpoint` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_ccr_high_setpoint_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 100.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
            self.ccr_high_setpoint = u8::MAX;
            return self;
        }
        self.ccr_high_setpoint = unscaled as u8;
        self
    }

    /// Returns `ccr_high_setpoint_depth` in its scaled value. It returns invalid f64 when value is valid.
    pub fn ccr_high_setpoint_depth_scaled(&self) -> f64 {
        if self.ccr_high_setpoint_depth == u32::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.ccr_high_setpoint_depth as f64 / 1000.0 - 0.0
    }

    /// Set `ccr_high_setpoint_depth` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_ccr_high_setpoint_depth_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 1000.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u32::MAX as f64 {
            self.ccr_high_setpoint_depth = u32::MAX;
            return self;
        }
        self.ccr_high_setpoint_depth = unscaled as u32;
        self
    }

    /// Returns `last_stop_multiple` in its scaled value. It returns invalid f64 when value is valid.
    pub fn last_stop_multiple_scaled(&self) -> f64 {
        if self.last_stop_multiple == u8::MAX {
            return f64::from_bits(u64::MAX);
        }
        self.last_stop_multiple as f64 / 10.0 - 0.0
    }

    /// Set `last_stop_multiple` with scaled value, it will automatically be converted to its corresponding integer value.
    pub fn set_last_stop_multiple_scaled(&mut self, v: f64) -> &mut DiveSettings {
        let unscaled = (v + 0.0) * 10.0;
        if unscaled.is_nan() || unscaled.is_infinite() || unscaled > u8::MAX as f64 {
            self.last_stop_multiple = u8::MAX;
            return self;
        }
        self.last_stop_multiple = unscaled as u8;
        self
    }
}

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

impl From<&Message> for DiveSettings {
    /// from creates new DiveSettings struct based on given mesg.
    fn from(mesg: &Message) -> Self {
        let mut vals: [&Value; 255] = [const { &Value::Invalid }; 255];

        const KNOWN_NUMS: [u64; 4] = [242397216767, 0, 0, 6917529027641081856];
        let mut n = 0u64;
        for field in &mesg.fields {
            n += (KNOWN_NUMS[field.num as usize >> 6] >> (field.num & 63)) & 1 ^ 1
        }
        let mut unknown_fields: Vec<Field> = Vec::with_capacity(n as usize);

        for field in &mesg.fields {
            if (KNOWN_NUMS[field.num as usize >> 6] >> (field.num & 63)) & 1 == 0 {
                unknown_fields.push(field.clone());
                continue;
            }
            vals[field.num as usize] = &field.value;
        }

        Self {
            timestamp: typedef::DateTime(vals[253].as_u32()),
            message_index: typedef::MessageIndex(vals[254].as_u16()),
            name: vals[0].as_string(),
            model: typedef::TissueModelType(vals[1].as_u8()),
            gf_low: vals[2].as_u8(),
            gf_high: vals[3].as_u8(),
            water_type: typedef::WaterType(vals[4].as_u8()),
            water_density: vals[5].as_f32(),
            po2_warn: vals[6].as_u8(),
            po2_critical: vals[7].as_u8(),
            po2_deco: vals[8].as_u8(),
            safety_stop_enabled: typedef::Bool(vals[9].as_u8()),
            bottom_depth: vals[10].as_f32(),
            bottom_time: vals[11].as_u32(),
            apnea_countdown_enabled: typedef::Bool(vals[12].as_u8()),
            apnea_countdown_time: vals[13].as_u32(),
            backlight_mode: typedef::DiveBacklightMode(vals[14].as_u8()),
            backlight_brightness: vals[15].as_u8(),
            backlight_timeout: typedef::BacklightTimeout(vals[16].as_u8()),
            repeat_dive_interval: vals[17].as_u16(),
            safety_stop_time: vals[18].as_u16(),
            heart_rate_source_type: typedef::SourceType(vals[19].as_u8()),
            heart_rate_source: vals[20].as_u8(),
            travel_gas: typedef::MessageIndex(vals[21].as_u16()),
            ccr_low_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(vals[22].as_u8()),
            ccr_low_setpoint: vals[23].as_u8(),
            ccr_low_setpoint_depth: vals[24].as_u32(),
            ccr_high_setpoint_switch_mode: typedef::CcrSetpointSwitchMode(vals[25].as_u8()),
            ccr_high_setpoint: vals[26].as_u8(),
            ccr_high_setpoint_depth: vals[27].as_u32(),
            gas_consumption_display: typedef::GasConsumptionRateType(vals[29].as_u8()),
            up_key_enabled: typedef::Bool(vals[30].as_u8()),
            dive_sounds: typedef::Tone(vals[35].as_u8()),
            last_stop_multiple: vals[36].as_u8(),
            no_fly_time_mode: typedef::NoFlyTimeMode(vals[37].as_u8()),
            unknown_fields,
            developer_fields: mesg.developer_fields.clone(),
        }
    }
}

impl From<DiveSettings> for Message {
    fn from(m: DiveSettings) -> Self {
        let mut arr = [const {
            Field {
                num: 0,
                profile_type: ProfileType(0),
                value: Value::Invalid,
                is_expanded: false,
            }
        }; 35];
        let mut len = 0usize;

        if m.timestamp != typedef::DateTime(u32::MAX) {
            arr[len] = Field {
                num: 253,
                profile_type: ProfileType::DATE_TIME,
                value: Value::Uint32(m.timestamp.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.message_index != typedef::MessageIndex(u16::MAX) {
            arr[len] = Field {
                num: 254,
                profile_type: ProfileType::MESSAGE_INDEX,
                value: Value::Uint16(m.message_index.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.name != String::new() {
            arr[len] = Field {
                num: 0,
                profile_type: ProfileType::STRING,
                value: Value::String(m.name),
                is_expanded: false,
            };
            len += 1;
        }
        if m.model != typedef::TissueModelType(u8::MAX) {
            arr[len] = Field {
                num: 1,
                profile_type: ProfileType::TISSUE_MODEL_TYPE,
                value: Value::Uint8(m.model.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.gf_low != u8::MAX {
            arr[len] = Field {
                num: 2,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.gf_low),
                is_expanded: false,
            };
            len += 1;
        }
        if m.gf_high != u8::MAX {
            arr[len] = Field {
                num: 3,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.gf_high),
                is_expanded: false,
            };
            len += 1;
        }
        if m.water_type != typedef::WaterType(u8::MAX) {
            arr[len] = Field {
                num: 4,
                profile_type: ProfileType::WATER_TYPE,
                value: Value::Uint8(m.water_type.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.water_density != f32::MAX {
            arr[len] = Field {
                num: 5,
                profile_type: ProfileType::FLOAT32,
                value: Value::Float32(m.water_density),
                is_expanded: false,
            };
            len += 1;
        }
        if m.po2_warn != u8::MAX {
            arr[len] = Field {
                num: 6,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.po2_warn),
                is_expanded: false,
            };
            len += 1;
        }
        if m.po2_critical != u8::MAX {
            arr[len] = Field {
                num: 7,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.po2_critical),
                is_expanded: false,
            };
            len += 1;
        }
        if m.po2_deco != u8::MAX {
            arr[len] = Field {
                num: 8,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.po2_deco),
                is_expanded: false,
            };
            len += 1;
        }
        if m.safety_stop_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 9,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.safety_stop_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.bottom_depth != f32::MAX {
            arr[len] = Field {
                num: 10,
                profile_type: ProfileType::FLOAT32,
                value: Value::Float32(m.bottom_depth),
                is_expanded: false,
            };
            len += 1;
        }
        if m.bottom_time != u32::MAX {
            arr[len] = Field {
                num: 11,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.bottom_time),
                is_expanded: false,
            };
            len += 1;
        }
        if m.apnea_countdown_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 12,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.apnea_countdown_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.apnea_countdown_time != u32::MAX {
            arr[len] = Field {
                num: 13,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.apnea_countdown_time),
                is_expanded: false,
            };
            len += 1;
        }
        if m.backlight_mode != typedef::DiveBacklightMode(u8::MAX) {
            arr[len] = Field {
                num: 14,
                profile_type: ProfileType::DIVE_BACKLIGHT_MODE,
                value: Value::Uint8(m.backlight_mode.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.backlight_brightness != u8::MAX {
            arr[len] = Field {
                num: 15,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.backlight_brightness),
                is_expanded: false,
            };
            len += 1;
        }
        if m.backlight_timeout != typedef::BacklightTimeout(u8::MAX) {
            arr[len] = Field {
                num: 16,
                profile_type: ProfileType::BACKLIGHT_TIMEOUT,
                value: Value::Uint8(m.backlight_timeout.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.repeat_dive_interval != u16::MAX {
            arr[len] = Field {
                num: 17,
                profile_type: ProfileType::UINT16,
                value: Value::Uint16(m.repeat_dive_interval),
                is_expanded: false,
            };
            len += 1;
        }
        if m.safety_stop_time != u16::MAX {
            arr[len] = Field {
                num: 18,
                profile_type: ProfileType::UINT16,
                value: Value::Uint16(m.safety_stop_time),
                is_expanded: false,
            };
            len += 1;
        }
        if m.heart_rate_source_type != typedef::SourceType(u8::MAX) {
            arr[len] = Field {
                num: 19,
                profile_type: ProfileType::SOURCE_TYPE,
                value: Value::Uint8(m.heart_rate_source_type.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.heart_rate_source != u8::MAX {
            arr[len] = Field {
                num: 20,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.heart_rate_source),
                is_expanded: false,
            };
            len += 1;
        }
        if m.travel_gas != typedef::MessageIndex(u16::MAX) {
            arr[len] = Field {
                num: 21,
                profile_type: ProfileType::MESSAGE_INDEX,
                value: Value::Uint16(m.travel_gas.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ccr_low_setpoint_switch_mode != typedef::CcrSetpointSwitchMode(u8::MAX) {
            arr[len] = Field {
                num: 22,
                profile_type: ProfileType::CCR_SETPOINT_SWITCH_MODE,
                value: Value::Uint8(m.ccr_low_setpoint_switch_mode.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ccr_low_setpoint != u8::MAX {
            arr[len] = Field {
                num: 23,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.ccr_low_setpoint),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ccr_low_setpoint_depth != u32::MAX {
            arr[len] = Field {
                num: 24,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.ccr_low_setpoint_depth),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ccr_high_setpoint_switch_mode != typedef::CcrSetpointSwitchMode(u8::MAX) {
            arr[len] = Field {
                num: 25,
                profile_type: ProfileType::CCR_SETPOINT_SWITCH_MODE,
                value: Value::Uint8(m.ccr_high_setpoint_switch_mode.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ccr_high_setpoint != u8::MAX {
            arr[len] = Field {
                num: 26,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.ccr_high_setpoint),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ccr_high_setpoint_depth != u32::MAX {
            arr[len] = Field {
                num: 27,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.ccr_high_setpoint_depth),
                is_expanded: false,
            };
            len += 1;
        }
        if m.gas_consumption_display != typedef::GasConsumptionRateType(u8::MAX) {
            arr[len] = Field {
                num: 29,
                profile_type: ProfileType::GAS_CONSUMPTION_RATE_TYPE,
                value: Value::Uint8(m.gas_consumption_display.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.up_key_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 30,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.up_key_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.dive_sounds != typedef::Tone(u8::MAX) {
            arr[len] = Field {
                num: 35,
                profile_type: ProfileType::TONE,
                value: Value::Uint8(m.dive_sounds.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.last_stop_multiple != u8::MAX {
            arr[len] = Field {
                num: 36,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.last_stop_multiple),
                is_expanded: false,
            };
            len += 1;
        }
        if m.no_fly_time_mode != typedef::NoFlyTimeMode(u8::MAX) {
            arr[len] = Field {
                num: 37,
                profile_type: ProfileType::NO_FLY_TIME_MODE,
                value: Value::Uint8(m.no_fly_time_mode.0),
                is_expanded: false,
            };
            len += 1;
        }

        Message {
            header: 0,
            num: typedef::MesgNum::DIVE_SETTINGS,
            fields: {
                let mut fields: Vec<Field> = Vec::with_capacity(len + m.unknown_fields.len());
                fields.extend_from_slice(&arr[..len]);
                fields.extend_from_slice(&m.unknown_fields);
                fields
            },
            developer_fields: m.developer_fields,
        }
    }
}