use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FrameHeader {
pub correlation_id: Uuid,
pub driver_id: Uuid,
pub width: u32,
pub height: u32,
pub bit_depth: u8,
#[serde(skip_serializing_if = "Option::is_none")]
pub bayer: Option<String>,
pub timestamp_ns: u64,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn frame_header_roundtrip() {
let h = FrameHeader {
correlation_id: Uuid::now_v7(),
driver_id: Uuid::now_v7(),
width: 6248,
height: 4176,
bit_depth: 16,
bayer: Some("RGGB".into()),
timestamp_ns: 1_700_000_000_000_000_000,
};
let json = serde_json::to_string(&h).unwrap();
let back: FrameHeader = serde_json::from_str(&json).unwrap();
assert_eq!(back.width, 6248);
assert_eq!(back.bayer.as_deref(), Some("RGGB"));
}
#[test]
fn mono_frame_omits_bayer() {
let h = FrameHeader {
correlation_id: Uuid::now_v7(),
driver_id: Uuid::now_v7(),
width: 1280,
height: 960,
bit_depth: 16,
bayer: None,
timestamp_ns: 0,
};
let json = serde_json::to_string(&h).unwrap();
assert!(!json.contains("bayer"));
}
}