use alloc::string::String;
#[cfg(feature = "std")]
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CaptureOp {
PutRecord,
PutRecords,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CaptureRecord {
pub op: CaptureOp,
pub ts: u64,
pub stream: String,
pub partition_key: String,
pub data: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub explicit_hash_key: Option<String>,
pub sequence_number: String,
pub shard_id: String,
}
#[cfg(feature = "std")]
pub fn read_capture_file(path: &std::path::Path) -> std::io::Result<Vec<CaptureRecord>> {
use std::fs::File;
use std::io::{BufRead, BufReader};
let file = File::open(path)?;
let reader = BufReader::new(file);
let mut records = Vec::new();
for line in reader.lines() {
let line = line?;
if line.trim().is_empty() {
continue;
}
match serde_json::from_str::<CaptureRecord>(&line) {
Ok(record) => records.push(record),
Err(error) => eprintln!("capture: skipping malformed line: {error}"),
}
}
Ok(records)
}