use serde::{Deserialize, Serialize};
use super::data_models::PredictionTrieNode;
pub const CURRENT_VERSION: &str = "1.0";
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrieEnvelope {
pub version: String,
pub generated_at: String,
pub workflow_name: String,
pub root: PredictionTrieNode,
}
impl TrieEnvelope {
pub fn new(root: PredictionTrieNode, workflow_name: impl Into<String>) -> Self {
Self {
version: CURRENT_VERSION.to_string(),
generated_at: chrono::Utc::now().to_rfc3339(),
workflow_name: workflow_name.into(),
root,
}
}
pub fn to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(self)
}
pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(json)
}
}
#[cfg(test)]
#[path = "../../tests/unit/trie/serialization_tests.rs"]
mod tests;