rustyfit 0.4.1

This project hosts the Rust implementation for The Flexible and Interoperable Data Transfer (FIT) Protocol
Documentation
// 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)]
/// Connectivity is a Connectivity message.
pub struct Connectivity {
    /// Use Bluetooth for connectivity features
    pub bluetooth_enabled: typedef::Bool,
    /// Use Bluetooth Low Energy for connectivity features
    pub bluetooth_le_enabled: typedef::Bool,
    /// Use ANT for connectivity features
    pub ant_enabled: typedef::Bool,
    pub name: String,
    pub live_tracking_enabled: typedef::Bool,
    pub weather_conditions_enabled: typedef::Bool,
    pub weather_alerts_enabled: typedef::Bool,
    pub auto_activity_upload_enabled: typedef::Bool,
    pub course_download_enabled: typedef::Bool,
    pub workout_download_enabled: typedef::Bool,
    pub gps_ephemeris_download_enabled: typedef::Bool,
    pub incident_detection_enabled: typedef::Bool,
    pub grouptrack_enabled: typedef::Bool,
    /// 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 Connectivity {
    /// Value's type: `u8`
    pub const BLUETOOTH_ENABLED: u8 = 0;
    /// Value's type: `u8`
    pub const BLUETOOTH_LE_ENABLED: u8 = 1;
    /// Value's type: `u8`
    pub const ANT_ENABLED: u8 = 2;
    /// Value's type: `String`
    pub const NAME: u8 = 3;
    /// Value's type: `u8`
    pub const LIVE_TRACKING_ENABLED: u8 = 4;
    /// Value's type: `u8`
    pub const WEATHER_CONDITIONS_ENABLED: u8 = 5;
    /// Value's type: `u8`
    pub const WEATHER_ALERTS_ENABLED: u8 = 6;
    /// Value's type: `u8`
    pub const AUTO_ACTIVITY_UPLOAD_ENABLED: u8 = 7;
    /// Value's type: `u8`
    pub const COURSE_DOWNLOAD_ENABLED: u8 = 8;
    /// Value's type: `u8`
    pub const WORKOUT_DOWNLOAD_ENABLED: u8 = 9;
    /// Value's type: `u8`
    pub const GPS_EPHEMERIS_DOWNLOAD_ENABLED: u8 = 10;
    /// Value's type: `u8`
    pub const INCIDENT_DETECTION_ENABLED: u8 = 11;
    /// Value's type: `u8`
    pub const GROUPTRACK_ENABLED: u8 = 12;

    /// Create new Connectivity with all fields being set to its corresponding invalid value.
    pub const fn new() -> Self {
        Self {
            bluetooth_enabled: typedef::Bool(u8::MAX),
            bluetooth_le_enabled: typedef::Bool(u8::MAX),
            ant_enabled: typedef::Bool(u8::MAX),
            name: String::new(),
            live_tracking_enabled: typedef::Bool(u8::MAX),
            weather_conditions_enabled: typedef::Bool(u8::MAX),
            weather_alerts_enabled: typedef::Bool(u8::MAX),
            auto_activity_upload_enabled: typedef::Bool(u8::MAX),
            course_download_enabled: typedef::Bool(u8::MAX),
            workout_download_enabled: typedef::Bool(u8::MAX),
            gps_ephemeris_download_enabled: typedef::Bool(u8::MAX),
            incident_detection_enabled: typedef::Bool(u8::MAX),
            grouptrack_enabled: typedef::Bool(u8::MAX),
            unknown_fields: Vec::new(),
            developer_fields: Vec::new(),
        }
    }
}

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

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

        const KNOWN_NUMS: [u64; 4] = [8191, 0, 0, 0];
        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 {
            bluetooth_enabled: typedef::Bool(vals[0].as_u8()),
            bluetooth_le_enabled: typedef::Bool(vals[1].as_u8()),
            ant_enabled: typedef::Bool(vals[2].as_u8()),
            name: vals[3].as_string(),
            live_tracking_enabled: typedef::Bool(vals[4].as_u8()),
            weather_conditions_enabled: typedef::Bool(vals[5].as_u8()),
            weather_alerts_enabled: typedef::Bool(vals[6].as_u8()),
            auto_activity_upload_enabled: typedef::Bool(vals[7].as_u8()),
            course_download_enabled: typedef::Bool(vals[8].as_u8()),
            workout_download_enabled: typedef::Bool(vals[9].as_u8()),
            gps_ephemeris_download_enabled: typedef::Bool(vals[10].as_u8()),
            incident_detection_enabled: typedef::Bool(vals[11].as_u8()),
            grouptrack_enabled: typedef::Bool(vals[12].as_u8()),
            unknown_fields,
            developer_fields: mesg.developer_fields.clone(),
        }
    }
}

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

        if m.bluetooth_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 0,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.bluetooth_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.bluetooth_le_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 1,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.bluetooth_le_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.ant_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 2,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.ant_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.name != String::new() {
            arr[len] = Field {
                num: 3,
                profile_type: ProfileType::STRING,
                value: Value::String(m.name),
                is_expanded: false,
            };
            len += 1;
        }
        if m.live_tracking_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 4,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.live_tracking_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.weather_conditions_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 5,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.weather_conditions_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.weather_alerts_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 6,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.weather_alerts_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.auto_activity_upload_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 7,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.auto_activity_upload_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.course_download_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 8,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.course_download_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.workout_download_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 9,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.workout_download_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.gps_ephemeris_download_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 10,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.gps_ephemeris_download_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.incident_detection_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 11,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.incident_detection_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.grouptrack_enabled != typedef::Bool(u8::MAX) {
            arr[len] = Field {
                num: 12,
                profile_type: ProfileType::BOOL,
                value: Value::Uint8(m.grouptrack_enabled.0),
                is_expanded: false,
            };
            len += 1;
        }

        Message {
            header: 0,
            num: typedef::MesgNum::CONNECTIVITY,
            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,
        }
    }
}