#![allow(unused, clippy::comparison_to_empty, clippy::manual_range_patterns)]
use crate::profile::{ProfileType, typedef};
use crate::proto::*;
#[derive(Debug, Clone)]
pub struct Connectivity {
pub bluetooth_enabled: typedef::Bool,
pub bluetooth_le_enabled: typedef::Bool,
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,
pub unknown_fields: Vec<Field>,
pub developer_fields: Vec<DeveloperField>,
}
impl Connectivity {
pub const BLUETOOTH_ENABLED: u8 = 0;
pub const BLUETOOTH_LE_ENABLED: u8 = 1;
pub const ANT_ENABLED: u8 = 2;
pub const NAME: u8 = 3;
pub const LIVE_TRACKING_ENABLED: u8 = 4;
pub const WEATHER_CONDITIONS_ENABLED: u8 = 5;
pub const WEATHER_ALERTS_ENABLED: u8 = 6;
pub const AUTO_ACTIVITY_UPLOAD_ENABLED: u8 = 7;
pub const COURSE_DOWNLOAD_ENABLED: u8 = 8;
pub const WORKOUT_DOWNLOAD_ENABLED: u8 = 9;
pub const GPS_EPHEMERIS_DOWNLOAD_ENABLED: u8 = 10;
pub const INCIDENT_DETECTION_ENABLED: u8 = 11;
pub const GROUPTRACK_ENABLED: u8 = 12;
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 {
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,
}
}
}