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)]
/// DeveloperDataId is a DeveloperDataId message.
pub struct DeveloperDataId {
    pub developer_id: Vec<u8>,
    pub application_id: Vec<u8>,
    pub manufacturer_id: typedef::Manufacturer,
    pub developer_data_index: u8,
    pub application_version: u32,
    /// unknown_fields are fields that are exist but they are not defined in Profile.xlsx
    pub unknown_fields: Vec<Field>,
}

impl DeveloperDataId {
    /// Value's type: `Vec<u8>`
    pub const DEVELOPER_ID: u8 = 0;
    /// Value's type: `Vec<u8>`
    pub const APPLICATION_ID: u8 = 1;
    /// Value's type: `u16`
    pub const MANUFACTURER_ID: u8 = 2;
    /// Value's type: `u8`
    pub const DEVELOPER_DATA_INDEX: u8 = 3;
    /// Value's type: `u32`
    pub const APPLICATION_VERSION: u8 = 4;

    /// Create new DeveloperDataId with all fields being set to its corresponding invalid value.
    pub const fn new() -> Self {
        Self {
            developer_id: Vec::<u8>::new(),
            application_id: Vec::<u8>::new(),
            manufacturer_id: typedef::Manufacturer(u16::MAX),
            developer_data_index: u8::MAX,
            application_version: u32::MAX,
            unknown_fields: Vec::new(),
        }
    }
}

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

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

        const KNOWN_NUMS: [u64; 4] = [31, 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 {
            developer_id: vals[0].as_vec_u8(),
            application_id: vals[1].as_vec_u8(),
            manufacturer_id: typedef::Manufacturer(vals[2].as_u16()),
            developer_data_index: vals[3].as_u8(),
            application_version: vals[4].as_u32(),
            unknown_fields,
        }
    }
}

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

        if m.developer_id != Vec::<u8>::new() {
            arr[len] = Field {
                num: 0,
                profile_type: ProfileType::BYTE,
                value: Value::VecUint8(m.developer_id),
                is_expanded: false,
            };
            len += 1;
        }
        if m.application_id != Vec::<u8>::new() {
            arr[len] = Field {
                num: 1,
                profile_type: ProfileType::BYTE,
                value: Value::VecUint8(m.application_id),
                is_expanded: false,
            };
            len += 1;
        }
        if m.manufacturer_id != typedef::Manufacturer(u16::MAX) {
            arr[len] = Field {
                num: 2,
                profile_type: ProfileType::MANUFACTURER,
                value: Value::Uint16(m.manufacturer_id.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.developer_data_index != u8::MAX {
            arr[len] = Field {
                num: 3,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.developer_data_index),
                is_expanded: false,
            };
            len += 1;
        }
        if m.application_version != u32::MAX {
            arr[len] = Field {
                num: 4,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.application_version),
                is_expanded: false,
            };
            len += 1;
        }

        Message {
            header: 0,
            num: typedef::MesgNum::DEVELOPER_DATA_ID,
            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: Vec::new(),
        }
    }
}