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)]
/// VideoClip is a VideoClip message.
pub struct VideoClip {
    pub clip_number: u16,
    pub start_timestamp: typedef::DateTime,
    pub start_timestamp_ms: u16,
    pub end_timestamp: typedef::DateTime,
    pub end_timestamp_ms: u16,
    /// Units: ms; Start of clip in video time
    pub clip_start: u32,
    /// Units: ms; End of clip in video time
    pub clip_end: u32,
    /// 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 VideoClip {
    /// Value's type: `u16`
    pub const CLIP_NUMBER: u8 = 0;
    /// Value's type: `u32`
    pub const START_TIMESTAMP: u8 = 1;
    /// Value's type: `u16`
    pub const START_TIMESTAMP_MS: u8 = 2;
    /// Value's type: `u32`
    pub const END_TIMESTAMP: u8 = 3;
    /// Value's type: `u16`
    pub const END_TIMESTAMP_MS: u8 = 4;
    /// Value's type: `u32`; Units: `ms`
    pub const CLIP_START: u8 = 6;
    /// Value's type: `u32`; Units: `ms`
    pub const CLIP_END: u8 = 7;

    /// Create new VideoClip with all fields being set to its corresponding invalid value.
    pub const fn new() -> Self {
        Self {
            clip_number: u16::MAX,
            start_timestamp: typedef::DateTime(u32::MAX),
            start_timestamp_ms: u16::MAX,
            end_timestamp: typedef::DateTime(u32::MAX),
            end_timestamp_ms: u16::MAX,
            clip_start: u32::MAX,
            clip_end: u32::MAX,
            unknown_fields: Vec::new(),
            developer_fields: Vec::new(),
        }
    }
}

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

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

        const KNOWN_NUMS: [u64; 4] = [223, 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 {
            clip_number: vals[0].as_u16(),
            start_timestamp: typedef::DateTime(vals[1].as_u32()),
            start_timestamp_ms: vals[2].as_u16(),
            end_timestamp: typedef::DateTime(vals[3].as_u32()),
            end_timestamp_ms: vals[4].as_u16(),
            clip_start: vals[6].as_u32(),
            clip_end: vals[7].as_u32(),
            unknown_fields,
            developer_fields: mesg.developer_fields.clone(),
        }
    }
}

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

        if m.clip_number != u16::MAX {
            arr[len] = Field {
                num: 0,
                profile_type: ProfileType::UINT16,
                value: Value::Uint16(m.clip_number),
                is_expanded: false,
            };
            len += 1;
        }
        if m.start_timestamp != typedef::DateTime(u32::MAX) {
            arr[len] = Field {
                num: 1,
                profile_type: ProfileType::DATE_TIME,
                value: Value::Uint32(m.start_timestamp.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.start_timestamp_ms != u16::MAX {
            arr[len] = Field {
                num: 2,
                profile_type: ProfileType::UINT16,
                value: Value::Uint16(m.start_timestamp_ms),
                is_expanded: false,
            };
            len += 1;
        }
        if m.end_timestamp != typedef::DateTime(u32::MAX) {
            arr[len] = Field {
                num: 3,
                profile_type: ProfileType::DATE_TIME,
                value: Value::Uint32(m.end_timestamp.0),
                is_expanded: false,
            };
            len += 1;
        }
        if m.end_timestamp_ms != u16::MAX {
            arr[len] = Field {
                num: 4,
                profile_type: ProfileType::UINT16,
                value: Value::Uint16(m.end_timestamp_ms),
                is_expanded: false,
            };
            len += 1;
        }
        if m.clip_start != u32::MAX {
            arr[len] = Field {
                num: 6,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.clip_start),
                is_expanded: false,
            };
            len += 1;
        }
        if m.clip_end != u32::MAX {
            arr[len] = Field {
                num: 7,
                profile_type: ProfileType::UINT32,
                value: Value::Uint32(m.clip_end),
                is_expanded: false,
            };
            len += 1;
        }

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