update serialization

This commit is contained in:
csehviktor
2025-07-08 14:47:52 +02:00
parent bf366cdad0
commit cf92638739
5 changed files with 20 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ pub mod metrics;
pub const MQTT_TOPIC: &str = "system/metrics";
pub const MQTT_SEND_INTERVAL: u64 = 5;
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StatusMessage {
pub agent: String,
pub metrics: Metrics,
@@ -36,3 +36,9 @@ impl<'a> TryFrom<&'a [u8]> for StatusMessage {
serde_json::from_slice(value)
}
}
impl From<StatusMessage> for String {
fn from(msg: StatusMessage) -> String {
serde_json::to_string(&msg).unwrap_or_else(|_| String::new())
}
}