Now using macaddr datatype and added test for adding devices and displaynames
All checks were successful
Build Project / test (push) Successful in 6m32s
All checks were successful
Build Project / test (push) Successful in 6m32s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
||||
use sqlx::types::mac_address::MacAddress;
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
pub struct TelemetryMessage {
|
||||
@@ -32,8 +33,26 @@ pub struct ValueMessage {
|
||||
pub timestamp: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Device {
|
||||
pub display_name: Option<String>,
|
||||
pub id: String
|
||||
pub id: MacAddress
|
||||
}
|
||||
|
||||
|
||||
impl Serialize for Device {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_struct("Device", 2)?;
|
||||
|
||||
// Serialize each field with custom logic
|
||||
let bytes = self.id.bytes();
|
||||
state.serialize_field("display_name", &self.display_name)?;
|
||||
state.serialize_field("id", &format!("{}{}{}{}{}{}", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]))?;
|
||||
|
||||
// End the serialization process
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user