use crate::flags::ParseFlags;
use crate::lookup::Encoding;
use crate::record::Record;
use crate::selection::Selections;
use std::fmt;
use std::sync::Arc;
use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FormatVersion {
V2,
V3,
}
impl FormatVersion {
#[must_use]
pub fn major(self) -> u8 {
match self {
FormatVersion::V2 => 2,
FormatVersion::V3 => 3,
}
}
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PackOptions {
pub format: Option<FormatVersion>,
pub record_length: Option<usize>,
pub encoding: Option<Encoding>,
pub extra_headers: Option<String>,
pub flush: bool,
pub flush_idle: Option<Duration>,
pub keep_data: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum Versions {
#[default]
Merge,
Separate,
Assign(u8),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum RecordList {
#[default]
Off,
WithExtras,
WithoutExtras,
}
pub type ToleranceFn = Arc<dyn Fn(&Record) -> f64 + Send + Sync>;
#[derive(Clone, Default)]
pub struct Tolerance {
pub time: Option<ToleranceFn>,
pub samprate: Option<ToleranceFn>,
}
impl Tolerance {
pub fn with_samprate(f: impl Fn(&Record) -> f64 + Send + Sync + 'static) -> Self {
Tolerance { time: None, samprate: Some(Arc::new(f)) }
}
pub fn with_time(f: impl Fn(&Record) -> f64 + Send + Sync + 'static) -> Self {
Tolerance { time: Some(Arc::new(f)), samprate: None }
}
}
impl fmt::Debug for Tolerance {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let show = |c: &Option<ToleranceFn>| if c.is_some() { "custom" } else { "default" };
f.debug_struct("Tolerance")
.field("time", &show(&self.time))
.field("samprate", &show(&self.samprate))
.finish()
}
}
#[derive(Debug, Clone)]
pub struct TraceListOptions {
pub versions: Versions,
pub autoheal: bool,
pub tolerance: Tolerance,
pub record_list: RecordList,
pub update_time: bool,
}
impl Default for TraceListOptions {
fn default() -> Self {
TraceListOptions {
versions: Versions::Merge,
autoheal: true,
tolerance: Tolerance::default(),
record_list: RecordList::Off,
update_time: false,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ReadOptions {
pub flags: ParseFlags,
pub selections: Option<Selections>,
pub skip_adjacent_duplicates: bool,
pub path_range: bool,
}
impl ReadOptions {
#[must_use]
pub fn new(flags: ParseFlags) -> Self {
ReadOptions { flags, ..Default::default() }
}
}