use segment_buffer::{FlushPolicy, SegmentBuffer, SegmentConfig};
use tempfile::tempdir;
#[derive(serde::Serialize, serde::Deserialize, Clone)]
struct Item {
id: u64,
payload: String,
}
fn main() {
let tmp = tempdir().expect("tempdir");
let config = SegmentConfig::builder()
.flush_policy(FlushPolicy::Manual)
.max_size_bytes(u64::MAX)
.compression_level(3)
.build();
let buf: SegmentBuffer<Item> = SegmentBuffer::open(tmp.path(), config).expect("open");
let n = std::hint::black_box(200_000);
for i in 0..n {
let item = Item {
id: i,
payload: format!("payload-{i}"),
};
buf.append(item).expect("append");
buf.flush().expect("flush");
}
for batch in 0..200 {
let base = batch * 1000;
for i in 0..1000u64 {
let item = Item {
id: base + i,
payload: format!("payload-{base}-{i}"),
};
buf.append(item).expect("append");
}
buf.flush().expect("flush");
}
eprintln!("final seq: {}", buf.latest_sequence());
}