2021-05-22 17:05:13 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
pub type JsonValue = serde_json::Value;
|
|
|
|
pub type JsonObject = serde_json::Map<String, JsonValue>;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
pub struct Payload {
|
|
|
|
pub message_id: i32,
|
|
|
|
pub sent_by_device_id: String,
|
|
|
|
pub command: JsonObject,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
2021-05-27 13:33:29 +00:00
|
|
|
pub struct Request {
|
|
|
|
#[serde(default)]
|
|
|
|
pub headers: HashMap<String, String>,
|
|
|
|
pub message_ident: String,
|
|
|
|
pub key: String,
|
|
|
|
pub payload: Payload,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
pub struct Message {
|
2021-05-22 17:05:13 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub headers: HashMap<String, String>,
|
|
|
|
pub method: Option<String>,
|
|
|
|
#[serde(default)]
|
2021-05-27 13:33:29 +00:00
|
|
|
pub payloads: Vec<JsonValue>,
|
2021-05-22 17:05:13 +00:00
|
|
|
pub uri: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
#[serde(tag = "type", rename_all = "snake_case")]
|
2021-05-27 13:33:29 +00:00
|
|
|
pub(super) enum MessageOrRequest {
|
|
|
|
Message(Message),
|
|
|
|
Request(Request),
|
2021-05-22 17:05:13 +00:00
|
|
|
}
|