rustyfit 0.8.1

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
// 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::manual_range_patterns)]

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

#[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::new(),
            application_id: Vec::new(),
            manufacturer_id: typedef::Manufacturer(u16::MAX),
            developer_data_index: u8::MAX,
            application_version: u32::MAX,
            unknown_fields: Vec::new(),
        }
    }

    fn count_valid_fields(&self) -> usize {
        (!self.developer_id.is_empty()) as usize
            + (!self.application_id.is_empty()) as usize
            + (self.manufacturer_id != typedef::Manufacturer(u16::MAX)) as usize
            + (self.developer_data_index != u8::MAX) as usize
            + (self.application_version != u32::MAX) as usize
    }
}

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 {
        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 v = Self::new();
        v.unknown_fields = Vec::<Field>::with_capacity(n as usize);

        for field in &mesg.fields {
            match field.num {
                0 => v.developer_id = field.value.to_vec_u8(),
                1 => v.application_id = field.value.to_vec_u8(),
                2 => v.manufacturer_id = typedef::Manufacturer(field.value.as_u16()),
                3 => v.developer_data_index = field.value.as_u8(),
                4 => v.application_version = field.value.as_u32(),
                _ => v.unknown_fields.push(field.clone()),
            };
        }

        v
    }
}

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

        if !m.developer_id.is_empty() {
            fields.push(Field {
                num: 0,
                profile_type: ProfileType::BYTE,
                value: Value::VecUint8(m.developer_id),
                is_expanded: false,
            });
        };
        if !m.application_id.is_empty() {
            fields.push(Field {
                num: 1,
                profile_type: ProfileType::BYTE,
                value: Value::VecUint8(m.application_id),
                is_expanded: false,
            });
        };
        if m.manufacturer_id != typedef::Manufacturer(u16::MAX) {
            fields.push(Field {
                num: 2,
                profile_type: ProfileType::MANUFACTURER,
                value: Value::Uint16(m.manufacturer_id.0),
                is_expanded: false,
            });
        };
        if m.developer_data_index != u8::MAX {
            fields.push(Field {
                num: 3,
                profile_type: ProfileType::UINT8,
                value: Value::Uint8(m.developer_data_index),
                is_expanded: false,
            });
        };
        if m.application_version != u32::MAX {
            fields.push(Field {
                num: 4,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.application_version),
                is_expanded: false,
            });
        };

        fields.extend_from_slice(&m.unknown_fields);

        Self {
            header: 0,
            num: typedef::MesgNum::DEVELOPER_DATA_ID,
            fields,
            developer_fields: Vec::new(),
        }
    }
}