#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::io::{Cursor, Read, Write};
use std::path::Path;
pub const MAGIC_HEADER: &[u8; 4] = b"PMAT";
pub const FORMAT_VERSION: u8 = 1;
const MAX_SNAPSHOT_COUNT: u32 = 10_000_000;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RecordingMetadata {
pub timestamp: u64,
pub program: String,
#[serde(default)]
pub args: Vec<String>,
#[serde(default)]
pub environment: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Snapshot {
pub frame_id: u64,
pub timestamp_relative_ms: u32,
#[serde(default)]
pub variables: HashMap<String, serde_json::Value>,
#[serde(default)]
pub stack_frames: Vec<StackFrame>,
pub instruction_pointer: u64,
#[serde(default)]
pub memory_snapshot: Option<Vec<u8>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StackFrame {
pub name: String,
#[serde(default)]
pub file: Option<String>,
#[serde(default)]
pub line: Option<u32>,
#[serde(default)]
pub locals: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct Recording {
metadata: RecordingMetadata,
snapshots: Vec<Snapshot>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum CompressionLevel {
#[default]
None,
Fast,
Best,
}
pub struct RecordingWriter<W: Write> {
writer: W,
metadata: RecordingMetadata,
snapshot_count: u32,
snapshots_buffer: Vec<u8>,
finalized: bool,
compression: CompressionLevel,
}
pub struct SnapshotSerializer {
buffer: Vec<u8>,
compression: CompressionLevel,
}
include!("recording_core.rs");
include!("recording_streaming.rs");
include!("recording_tests.rs");