48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use crate::data_type::DataType;
|
|
use crate::data_value::DataValue;
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct CommandParameterDefinition {
|
|
pub name: String,
|
|
pub data_type: DataType,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct CommandDefinition {
|
|
pub name: String,
|
|
pub parameters: Vec<CommandParameterDefinition>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct CommandHeader {
|
|
pub timestamp: DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub struct Command {
|
|
#[serde(flatten)]
|
|
pub header: CommandHeader,
|
|
pub parameters: HashMap<String, DataValue>,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Eq, Error)]
|
|
pub enum IntoCommandDefinitionError {
|
|
#[error("Parameter Missing: {0}")]
|
|
ParameterMissing(String),
|
|
#[error("Mismatched Type for {parameter}. {expected:?} expected")]
|
|
MismatchedType {
|
|
parameter: String,
|
|
expected: DataType,
|
|
},
|
|
}
|
|
|
|
pub trait IntoCommandDefinition: Sized {
|
|
fn create(name: String) -> CommandDefinition;
|
|
|
|
fn parse(command: Command) -> Result<Self, IntoCommandDefinitionError>;
|
|
}
|