axcp/
models.rs

1//! Data models for the AXCP protocol.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Represents a telemetry data point.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct TelemetryData {
9    /// The metric name.
10    pub metric: String,
11    /// The metric value.
12    pub value: f64,
13    /// Optional tags for the metric.
14    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
15    pub tags: HashMap<String, String>,
16    /// Timestamp in milliseconds since epoch.
17    pub timestamp: Option<i64>,
18}
19
20/// Represents a batch of telemetry data points.
21#[derive(Debug, Default, Serialize, Deserialize)]
22pub struct TelemetryBatch {
23    /// The telemetry data points in this batch.
24    pub points: Vec<TelemetryData>,
25}
26
27/// Configuration for the AXCP client.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct ClientConfig {
30    /// The base URL of the AXCP server.
31    pub base_url: String,
32    /// The API key for authentication.
33    pub api_key: Option<String>,
34    /// The timeout for requests in seconds.
35    #[serde(default = "default_timeout")]
36    pub timeout_secs: u64,
37    /// Whether to enable telemetry collection.
38    #[serde(default = "default_true")]
39    pub enable_telemetry: bool,
40}
41
42fn default_timeout() -> u64 {
43    30
44}
45
46fn default_true() -> bool {
47    true
48}
49
50impl Default for ClientConfig {
51    fn default() -> Self {
52        Self {
53            base_url: "http://localhost:8080".to_string(),
54            api_key: None,
55            timeout_secs: default_timeout(),
56            enable_telemetry: true,
57        }
58    }
59}