Struct s4lib::readers::fixedstructreader::FixedStructReader
source · pub struct FixedStructReader { /* private fields */ }
Expand description
A specialized reader that uses BlockReader
to read FixedStruct
entries in a file.
The FixedStructReader
converts \[u8\]
to FixedStruct
in
buffer_to_fixedstructptr
.
§Summary of operation
A FixedStructReader
first deteremines the FixedStructType
of the file
in preprocess_fixedstructtype
.
Then it scans all time values in each entry to determine the
order to process the entries in preprocess_timevalues
. This implies the
blockreader
must read the entire file into memory. So far, “in the wild”
user accounting records are only a few kilobytes at most. So reading the
entire file into memory should not put too much strain on memory usage.
The processing of time values is done first and for the entire file
because records may not be stored in chronological order.
Then the caller makes repeated calls to process_entry_at
which processes
the FixedStruct
s found in the file.
0x00 byte and 0xFF byte fixedstructs are considered a null entry and ignored.
XXX: not a rust “Reader”; does not implement trait Read
.
Implementations§
source§impl FixedStructReader
impl FixedStructReader
Implement the FixedStructReader.
sourcepub fn new(
path: FPath,
filetype: FileType,
blocksz: BlockSz,
tz_offset: FixedOffset,
dt_filter_after: DateTimeLOpt,
dt_filter_before: DateTimeLOpt
) -> ResultFixedStructReaderNewError
pub fn new( path: FPath, filetype: FileType, blocksz: BlockSz, tz_offset: FixedOffset, dt_filter_after: DateTimeLOpt, dt_filter_before: DateTimeLOpt ) -> ResultFixedStructReaderNewError
Create a new FixedStructReader
.
NOTE: this new()
calls BlockerReader.read_block
,
dissimilar from other
*Readers::new()
which try to avoid calls to read_block
.
This means the reading may return Done
(like if the file is empty) and
Done
must be reflected in the return value of new
. Hence this
function has a specialized return value.
sourcepub const fn blocksz(&self) -> BlockSz
pub const fn blocksz(&self) -> BlockSz
See BlockReader::blocksz
.
sourcepub const fn filesz(&self) -> FileSz
pub const fn filesz(&self) -> FileSz
See BlockReader::filesz
.
sourcepub const fn path(&self) -> &FPath
pub const fn path(&self) -> &FPath
See BlockReader::path
.
sourcepub fn mtime(&self) -> SystemTime
pub fn mtime(&self) -> SystemTime
See BlockReader::mtime
.
sourcepub fn count_entries_processed(&self) -> Count
pub fn count_entries_processed(&self) -> Count
Count
of FixedStruct
s processed by this FixedStructReader
(i.e. self.entries_processed
).
sourcepub fn entries_stored_highest(&self) -> usize
pub fn entries_stored_highest(&self) -> usize
“High watermark” of FixedStruct
stored in self.cache_entries
.
sourcepub const fn block_offset_at_file_offset(
&self,
fileoffset: FileOffset
) -> BlockOffset
pub const fn block_offset_at_file_offset( &self, fileoffset: FileOffset ) -> BlockOffset
sourcepub const fn file_offset_at_block_offset(
&self,
blockoffset: BlockOffset
) -> FileOffset
pub const fn file_offset_at_block_offset( &self, blockoffset: BlockOffset ) -> FileOffset
sourcepub const fn file_offset_at_block_offset_index(
&self,
blockoffset: BlockOffset,
blockindex: BlockIndex
) -> FileOffset
pub const fn file_offset_at_block_offset_index( &self, blockoffset: BlockOffset, blockindex: BlockIndex ) -> FileOffset
sourcepub const fn block_index_at_file_offset(
&self,
fileoffset: FileOffset
) -> BlockIndex
pub const fn block_index_at_file_offset( &self, fileoffset: FileOffset ) -> BlockIndex
sourcepub const fn count_blocks(&self) -> Count
pub const fn count_blocks(&self) -> Count
sourcepub const fn blockoffset_last(&self) -> BlockOffset
pub const fn blockoffset_last(&self) -> BlockOffset
sourcepub const fn fileoffset_last(&self) -> FileOffset
pub const fn fileoffset_last(&self) -> FileOffset
sourcepub const fn is_fileoffset_last(&self, fileoffset: FileOffset) -> bool
pub const fn is_fileoffset_last(&self, fileoffset: FileOffset) -> bool
Is the passed FileOffset
the last byte of the file?
sourcepub fn is_last(&self, fixedstruct: &FixedStruct) -> bool
pub fn is_last(&self, fixedstruct: &FixedStruct) -> bool
Is the passed FixedStruct
the last of the file?
sourcepub const fn fileoffset_to_fixedstructoffset(
&self,
fileoffset: FileOffset
) -> FileOffset
pub const fn fileoffset_to_fixedstructoffset( &self, fileoffset: FileOffset ) -> FileOffset
Return the FileOffset
that is adjusted to the beginning offset of
a fixedstruct
entry.
sourcepub fn fileoffset_first(&self) -> Option<FileOffset>
pub fn fileoffset_first(&self) -> Option<FileOffset>
Return the first file offset from self.map_tvpair_fo
for the first
entry as sorted by tv_pair_type
(datetime); i.e. the earliest entry.
Ties are broken by FileOffset
.
sourcepub const fn fixedstruct_size(&self) -> usize
pub const fn fixedstruct_size(&self) -> usize
The size in bytes of the FixedStruct
entries managed by this
FixedStructReader
.
sourcepub const fn fixedstruct_size_fo(&self) -> FileOffset
pub const fn fixedstruct_size_fo(&self) -> FileOffset
fixedstruct_size
as a FileOffset
.
sourcepub const fn fixedstruct_type(&self) -> FixedStructType
pub const fn fixedstruct_type(&self) -> FixedStructType
The FixedStructType
of the file.
sourcepub fn score_file(
blockreader: &mut BlockReader,
oneblock: bool,
types_to_bonus: HashMap<FixedStructType, Score>
) -> ResultFixedStructReaderScoreFileError
pub fn score_file( blockreader: &mut BlockReader, oneblock: bool, types_to_bonus: HashMap<FixedStructType, Score> ) -> ResultFixedStructReaderScoreFileError
Process entries for the file managed by the BlockReader
.
Find the entry with the highest “score” as judged by score_fixedstruct
.
Returns the highest scored FixedStructType
, that highest score,
and any processed FixedStruct
entries (referenced by a
FixedStructDynPtr
) in a list.
Each list entry is a tuple of the
the entries FileOffset
and the FixedStructDynPtr
.
The entries will presumably be stored in the
FixedStructReader
’s cache_entries
.
sourcepub fn process_entry_at(
&mut self,
fo: FileOffset,
buffer: &mut [u8]
) -> ResultS3FixedStructFind
pub fn process_entry_at( &mut self, fo: FileOffset, buffer: &mut [u8] ) -> ResultS3FixedStructFind
Process the data at FileOffset fo
. Transform it into a FixedStruct
using FixedStruct::new
.
But before that, check private self.cache_entries
in case the data at the fileoffset was already processed (transformed)
during FixedStructReader::new
.
Let the caller pass a buffer
to avoid this function having allocate.
This function does the bulk of file processing after the
FixedStructReader
has been initialized during
FixedStructReader::new
.
sourcepub fn entry_dt_after_or_before(
entry: &FixedStruct,
dt_filter: &DateTimeLOpt
) -> Result_Filter_DateTime1
pub fn entry_dt_after_or_before( entry: &FixedStruct, dt_filter: &DateTimeLOpt ) -> Result_Filter_DateTime1
Wrapper function for call to datetime::dt_after_or_before
using the
FixedStruct::dt
of the entry
.
sourcepub fn entry_pass_filters(
entry: &FixedStruct,
dt_filter_after: &DateTimeLOpt,
dt_filter_before: &DateTimeLOpt
) -> Result_Filter_DateTime2
pub fn entry_pass_filters( entry: &FixedStruct, dt_filter_after: &DateTimeLOpt, dt_filter_before: &DateTimeLOpt ) -> Result_Filter_DateTime2
Wrapper function for call to datetime::dt_pass_filters
using the
FixedStruct::dt
of the entry
.
sourcepub fn summary(&self) -> SummaryFixedStructReader
pub fn summary(&self) -> SummaryFixedStructReader
Return an up-to-date SummaryFixedStructReader
instance for this
FixedStructReader
.
sourcepub fn summary_complete(&self) -> Summary
pub fn summary_complete(&self) -> Summary
Return an up-to-date Summary
instance for this FixedStructReader
.