use crate::blob_meta::{BlobIndex, ElemKind};
#[derive(Clone)]
pub(super) struct BlobDescriptor {
pub seq: u64,
pub frame_start: u64,
pub frame_len: usize,
pub blob_offset: usize,
pub data_size: usize,
pub kind: ElemKind,
pub id_range: Option<(i64, i64)>,
pub index: Option<BlobIndex>,
pub tagdata: Option<Box<[u8]>>,
}
pub(super) enum ScannedBlob {
Candidate(BlobDescriptor),
Passthrough(BlobDescriptor),
}
pub(super) enum WorkerOutput {
FalsePositive(BlobDescriptor),
}
pub(super) enum DrainItem {
CopyRange {
seq: u64,
frame_start: u64,
frame_len: usize,
kind: ElemKind,
id_range: (i64, i64),
index: BlobIndex,
tagdata: Option<Box<[u8]>>,
},
OwnedBytes {
seq: u64,
frame_bytes: Vec<u8>,
kind: ElemKind,
id_range: (i64, i64),
count: u64,
},
Rewritten {
seq: u64,
framed_chunks: Vec<Vec<u8>>,
kind: ElemKind,
id_range: (i64, i64),
stats: super::stats::MergeStats,
},
}
impl BlobDescriptor {
pub(super) fn into_drain_copy_range(self) -> Option<DrainItem> {
let index = self.index?;
let id_range = self.id_range.unwrap_or((index.min_id, index.max_id));
Some(DrainItem::CopyRange {
seq: self.seq,
frame_start: self.frame_start,
frame_len: self.frame_len,
kind: self.kind,
id_range,
index,
tagdata: self.tagdata,
})
}
}
impl WorkerOutput {
pub(super) fn into_drain_item(self, fallback_count: u64) -> DrainItem {
match self {
WorkerOutput::FalsePositive(desc) => {
let seq = desc.seq;
let frame_start = desc.frame_start;
let frame_len = desc.frame_len;
let kind = desc.kind;
let id_range = desc.id_range.unwrap_or((0, 0));
let index = desc.index.unwrap_or(crate::blob_meta::BlobIndex {
kind,
min_id: id_range.0,
max_id: id_range.1,
count: fallback_count,
bbox: None,
});
DrainItem::CopyRange {
seq,
frame_start,
frame_len,
kind,
id_range,
index,
tagdata: desc.tagdata,
}
}
}
}
}
impl DrainItem {
pub(super) fn seq(&self) -> u64 {
match self {
DrainItem::CopyRange { seq, .. }
| DrainItem::OwnedBytes { seq, .. }
| DrainItem::Rewritten { seq, .. } => *seq,
}
}
pub(super) fn kind(&self) -> ElemKind {
match self {
DrainItem::CopyRange { kind, .. }
| DrainItem::OwnedBytes { kind, .. }
| DrainItem::Rewritten { kind, .. } => *kind,
}
}
pub(super) fn id_range(&self) -> (i64, i64) {
match self {
DrainItem::CopyRange { id_range, .. }
| DrainItem::OwnedBytes { id_range, .. }
| DrainItem::Rewritten { id_range, .. } => *id_range,
}
}
pub(super) fn byte_cost(&self) -> usize {
const DESCRIPTOR_OVERHEAD: usize = 64;
match self {
DrainItem::CopyRange { tagdata, .. } => {
DESCRIPTOR_OVERHEAD + tagdata.as_ref().map_or(0, |t| t.len())
}
DrainItem::OwnedBytes { frame_bytes, .. } => {
DESCRIPTOR_OVERHEAD + frame_bytes.len()
}
DrainItem::Rewritten { framed_chunks, .. } => {
DESCRIPTOR_OVERHEAD
+ framed_chunks.iter().map(Vec::len).sum::<usize>()
}
}
}
}