pub mod decoder;
pub mod encap;
pub mod encoder;
pub mod error;
pub mod payload;
pub mod smi;
pub mod sync;
pub mod truncate;
pub mod unit;
mod util;
mod width;
#[cfg(test)]
mod tests;
pub use error::Error;
use crate::config;
pub fn builder() -> Builder<unit::Reference> {
Default::default()
}
#[derive(Copy, Clone, Default)]
pub struct Builder<U = unit::Reference> {
field_widths: width::Widths,
unit: U,
hart_index_width: u8,
timestamp_width: u8,
trace_type_width: u8,
no_compress: bool,
}
impl Builder<unit::Reference> {
pub fn new() -> Self {
Default::default()
}
}
impl<U> Builder<U> {
pub fn with_params(self, params: &config::Parameters) -> Self {
Self {
field_widths: params.into(),
..self
}
}
pub fn for_unit<V>(self, unit: V) -> Builder<V> {
Builder {
field_widths: self.field_widths,
unit,
hart_index_width: self.hart_index_width,
timestamp_width: self.timestamp_width,
trace_type_width: self.trace_type_width,
no_compress: self.no_compress,
}
}
pub fn with_hart_index_width(self, hart_index_width: u8) -> Self {
Self {
hart_index_width,
..self
}
}
pub fn with_timestamp_width(self, timestamp_width: u8) -> Self {
Self {
timestamp_width,
..self
}
}
pub fn with_trace_type_width(self, trace_type_width: u8) -> Self {
Self {
trace_type_width,
..self
}
}
pub fn with_compression(self, compress: bool) -> Self {
Self {
no_compress: !compress,
..self
}
}
pub fn decoder(self, data: &[u8]) -> decoder::Decoder<'_, U> {
let mut res = decoder::Decoder::new(
self.field_widths,
self.unit,
self.hart_index_width,
self.timestamp_width,
self.trace_type_width,
);
res.reset(data);
res
}
pub fn encoder(self, buffer: &mut [u8]) -> encoder::Encoder<'_, U> {
let mut res = encoder::Encoder::new(
self.field_widths,
self.unit,
self.hart_index_width,
self.timestamp_width,
self.trace_type_width,
!self.no_compress,
);
res.reset(buffer);
res
}
}