mod can_dbc_logger_config;
pub use can_dbc_logger_config::CanDbcLoggerConfig;
use crate::writer::FlushPolicy;
pub struct CanDbcLoggerBuilder {
pub(super) dbc: dbc_rs::Dbc,
pub(super) config: CanDbcLoggerConfig,
pub(super) capacity: Option<usize>,
pub(super) flush_policy: Option<FlushPolicy>,
}
impl CanDbcLoggerBuilder {
pub fn new(dbc: dbc_rs::Dbc) -> Self {
Self {
dbc,
config: CanDbcLoggerConfig::default(),
capacity: None,
flush_policy: None,
}
}
pub fn store_raw_values(mut self, enabled: bool) -> Self {
self.config.store_raw_values = enabled;
self
}
pub fn include_units(mut self, enabled: bool) -> Self {
self.config.include_units = enabled;
self
}
pub fn include_limits(mut self, enabled: bool) -> Self {
self.config.include_limits = enabled;
self
}
pub fn include_conversions(mut self, enabled: bool) -> Self {
self.config.include_conversions = enabled;
self
}
pub fn include_value_descriptions(mut self, enabled: bool) -> Self {
self.config.include_value_descriptions = enabled;
self
}
pub fn with_capacity(mut self, capacity: usize) -> Self {
self.capacity = Some(capacity);
self
}
pub fn with_flush_policy(mut self, policy: FlushPolicy) -> Self {
self.flush_policy = Some(policy);
self
}
pub fn build(self) -> crate::Result<super::CanDbcLogger<crate::writer::VecWriter>> {
let mut writer = match self.capacity {
Some(cap) => {
crate::MdfWriter::from_writer(crate::writer::VecWriter::with_capacity(cap))
}
None => crate::MdfWriter::from_writer(crate::writer::VecWriter::new()),
};
if let Some(policy) = self.flush_policy {
writer.set_flush_policy(policy);
}
Ok(super::CanDbcLogger::with_config(
self.dbc,
writer,
self.config,
))
}
#[cfg(feature = "std")]
pub fn build_file(
self,
path: &str,
) -> crate::Result<super::CanDbcLogger<crate::writer::FileWriter>> {
let mut writer = match self.capacity {
Some(cap) => crate::MdfWriter::new_with_capacity(path, cap)?,
None => crate::MdfWriter::new(path)?,
};
if let Some(policy) = self.flush_policy {
writer.set_flush_policy(policy);
}
Ok(super::CanDbcLogger::with_config(
self.dbc,
writer,
self.config,
))
}
}