use serde::{Deserialize, Serialize};
use crate::header::BinlogHeader;
pub const MUNIN_JSONLOG_VERSION: u32 = 1;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JsonlogFile {
pub munin_jsonlog_version: u32,
pub header: JsonlogHeader,
pub strings: Vec<String>,
pub name_value_lists: Vec<Vec<[u32; 2]>>,
pub archives: Vec<ArchiveB64>,
pub events: Vec<JsonlogEvent>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct JsonlogHeader {
pub file_format_version: i32,
pub min_reader_version: i32,
}
impl From<BinlogHeader> for JsonlogHeader {
fn from(h: BinlogHeader) -> Self {
Self {
file_format_version: h.file_format_version,
min_reader_version: h.min_reader_version,
}
}
}
impl From<JsonlogHeader> for BinlogHeader {
fn from(h: JsonlogHeader) -> Self {
Self {
file_format_version: h.file_format_version,
min_reader_version: h.min_reader_version,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArchiveB64 {
pub data_b64: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JsonlogEvent {
pub kind: String,
pub byte_offset: u64,
#[serde(flatten)]
pub body: JsonlogEventBody,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum JsonlogEventBody {
Decoded(serde_json::Value),
PayloadB64(String),
}