• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jtmoon79 / super-speedy-syslog-searcher / 20603980203

30 Dec 2025 07:10PM UTC coverage: 67.773% (-2.0%) from 69.779%
20603980203

push

github

jtmoon79
(CI) s4_* --venv

15621 of 23049 relevant lines covered (67.77%)

123479.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.1
/src/readers/fixedstructreader.rs
1
// src/readers/fixedstructreader.rs
2

3
//! Implements a [`FixedStructReader`],
4
//! the driver of deriving [`FixedStruct`s] (acct/lastlog/utmp/etc.)
5
//! from a fixed C-struct format file using a [`BlockReader`].
6
//!
7
//! Sibling of [`SyslogProcessor`]. But simpler in a number of ways due to
8
//! predictable format of the fixedsturct files. Also, a `FixedStructReader`
9
//! does not presume entries are in chronological order.
10
//! Whereas `SyslogProcessor` presumes entries are in chronological order.
11
//! This makes a big difference for implementations.
12
//!
13
//! This is an _s4lib_ structure used by the binary program _s4_.
14
//!
15
//! Implements [Issue #70].
16
//!
17
//! [`FixedStructReader`]: self::FixedStructReader
18
//! [`FixedStruct`s]: crate::data::fixedstruct::FixedStruct
19
//! [`BlockReader`]: crate::readers::blockreader::BlockReader
20
//! [`SyslogProcessor`]: crate::readers::syslogprocessor::SyslogProcessor
21
//! [Issue #70]: https://github.com/jtmoon79/super-speedy-syslog-searcher/issues/70
22

23
// TODO: ask question on SO about difference in
24
//       `e_termination` and `e_exit` in `struct exit_status`
25
//       https://elixir.bootlin.com/glibc/glibc-2.37/source/bits/utmp.h#L48
26

27
use std::collections::{
28
    BTreeMap,
29
    LinkedList,
30
};
31
use std::fmt;
32
use std::io::{
33
    Error,
34
    ErrorKind,
35
    Result,
36
};
37

38
use ::more_asserts::{
39
    debug_assert_ge,
40
    debug_assert_le,
41
};
42
#[allow(unused_imports)]
43
use ::si_trace_print::{
44
    de,
45
    def1n,
46
    def1o,
47
    def1x,
48
    def1ñ,
49
    defn,
50
    defo,
51
    defx,
52
    defñ,
53
    den,
54
    deo,
55
    dex,
56
    deñ,
57
    pfn,
58
    pfo,
59
    pfx,
60
};
61

62
use crate::common::{
63
    debug_panic,
64
    Count,
65
    FPath,
66
    FileOffset,
67
    FileSz,
68
    FileType,
69
    FileTypeFixedStruct,
70
    ResultFind,
71
};
72
use crate::data::datetime::{
73
    dt_after_or_before,
74
    dt_pass_filters,
75
    DateTimeL,
76
    DateTimeLOpt,
77
    FixedOffset,
78
    Result_Filter_DateTime1,
79
    Result_Filter_DateTime2,
80
    SystemTime,
81
};
82
use crate::data::fixedstruct::{
83
    buffer_to_fixedstructptr,
84
    convert_datetime_tvpair,
85
    filesz_to_types,
86
    tv_pair_type,
87
    FixedStruct,
88
    FixedStructDynPtr,
89
    FixedStructType,
90
    FixedStructTypeSet,
91
    Score,
92
    ENTRY_SZ_MAX,
93
    ENTRY_SZ_MIN,
94
    TIMEVAL_SZ_MAX,
95
};
96
use crate::readers::blockreader::{
97
    BlockIndex,
98
    BlockOffset,
99
    BlockReader,
100
    BlockSz,
101
    ResultReadDataToBuffer,
102
};
103
use crate::readers::summary::Summary;
104
use crate::{
105
    de_err,
106
    de_wrn,
107
    e_err,
108
};
109

110
// -----------------
111
// FixedStructReader
112

113
/// Map [`FileOffset`] To [`FixedStruct`].
114
///
115
/// Storage for `FixedStruct` found from the underlying `BlockReader`.
116
/// FileOffset key is the first byte/offset that begins the `FixedStruct`.
117
///
118
/// [`FileOffset`]: crate::common::FileOffset
119
/// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
120
pub type FoToEntry = BTreeMap<FileOffset, FixedStruct>;
121

122
/// Map [`FileOffset`] To `FileOffset`
123
///
124
/// [`FileOffset`]: crate::common::FileOffset
125
pub type FoToFo = BTreeMap<FileOffset, FileOffset>;
126

127
pub type FoList = LinkedList<FileOffset>;
128

129
type MapTvPairToFo = BTreeMap<tv_pair_type, FileOffset>;
130

131
/// [`FixedStructReader.find`*] functions results.
132
///
133
/// [`FixedStructReader.find`*]: self::FixedStructReader#method.find_entry
134
pub type ResultFindFixedStruct = ResultFind<(FileOffset, FixedStruct), (Option<FileOffset>, Error)>;
135

136
pub type ResultFindFixedStructProcZeroBlock = ResultFind<(FixedStructType, Score, ListFileOffsetFixedStructPtr), Error>;
137

138
pub type ResultTvFo = Result<(usize, usize, usize, usize, MapTvPairToFo)>;
139

140
#[cfg(test)]
141
pub type DroppedBlocks = LinkedList<BlockOffset>;
142

143
type ListFileOffsetFixedStructPtr = LinkedList<(FileOffset, FixedStructDynPtr)>;
144

145
/// Enum return value for [`FixedStructReader::new`].
146
#[derive(Debug)]
147
pub enum ResultFixedStructReaderNew<E> {
148
    /// `FixedStructReader::new` was successful and returns the
149
    /// `FixedStructReader`
150
    FileOk(FixedStructReader),
151
    FileErrEmpty,
152
    FileErrTooSmall(String),
153
    /// No valid fixedstruct
154
    FileErrNoValidFixedStruct,
155
    /// No fixedstruct within the datetime filters
156
    FileErrNoFixedStructWithinDtFilters,
157
    /// Carries the `E` error data. This is how an [`Error`] is carried between
158
    /// a processing thread and the main printing thread
159
    FileErrIo(E),
160
}
161

162
pub type ResultFixedStructReaderNewError = ResultFixedStructReaderNew<Error>;
163

164
#[derive(Debug)]
165
pub enum ResultFixedStructReaderScoreFile<E> {
166
    /// `score_file` was successful; return the `FixedStructType`, `Score`,
167
    /// already processed `FixedStrcutDynPtr` entries (with associated offsets)
168
    FileOk(FixedStructType, Score, ListFileOffsetFixedStructPtr),
169
    FileErrEmpty,
170
    /// No valid fixedstruct
171
    FileErrNoValidFixedStruct,
172
    /// No high score for the file
173
    FileErrNoHighScore,
174
    /// Carries the `E` error data. This is how an [`Error`] is carried between
175
    /// a processing thread and the main printing thread
176
    FileErrIo(E),
177
}
178

179
pub type ResultFixedStructReaderScoreFileError = ResultFixedStructReaderScoreFile<Error>;
180

181
/// A specialized reader that uses [`BlockReader`] to read [`FixedStruct`]
182
/// entries in a file.
183
///
184
/// The `FixedStructReader` converts `\[u8\]` to `FixedStruct` in
185
/// [`buffer_to_fixedstructptr`].
186
///
187
/// ## Summary of operation
188
///
189
/// A `FixedStructReader` first deteremines the `FixedStructType` of the file
190
/// in [`preprocess_fixedstructtype`].
191
/// Then it scans all ***t***ime ***v***alues in each entry to determine the
192
/// order to process the entries in [`preprocess_timevalues`]. This implies the
193
/// `blockreader` must read the entire file into memory. So far, "in the wild"
194
/// user accounting records are only a few kilobytes at most. So reading the
195
/// entire file into memory should not put much strain on memory usage of a
196
/// typical desktop or server.
197
/// The processing of time values is done first and for the entire file
198
/// because records may not be stored in chronological order.
199
/// Then the caller makes repeated calls to [`process_entry_at`] which processes
200
/// the `FixedStruct`s found in the file.
201
///
202
/// 0x00 byte and 0xFF byte fixedstructs are considered a null entry and
203
/// ignored.
204
///
205
/// _XXX: not a rust "Reader"; does not implement trait [`Read`]._
206
///
207
/// [`buffer_to_fixedstructptr`]: crate::data::fixedstruct::buffer_to_fixedstructptr
208
/// [`BlockReader`]: crate::readers::blockreader::BlockReader
209
/// [`Read`]: std::io::Read
210
/// [`preprocess_fixedstructtype`]: FixedStructReader::preprocess_fixedstructtype
211
/// [`preprocess_timevalues`]: FixedStructReader::preprocess_timevalues
212
/// [`process_entry_at`]: FixedStructReader::process_entry_at
213
pub struct FixedStructReader {
214
    pub(crate) blockreader: BlockReader,
215
    fixedstruct_type: FixedStructType,
216
    filetype_fixedstruct: FileTypeFixedStruct,
217
    /// Size of a single [`FixedStruct`] entry.
218
    fixedstruct_size: usize,
219
    /// The highest score found during `preprocess_file`.
220
    /// Used to determine the `FixedStructType` of the file.
221
    high_score: Score,
222
    /// Timezone to use for conversions using function
223
    /// [`convert_tvpair_to_datetime`].
224
    ///
225
    /// [`convert_tvpair_to_datetime`]: crate::data::fixedstruct::convert_tvpair_to_datetime
226
    tz_offset: FixedOffset,
227
    /// A temporary hold for [`FixedStruct`] entries found
228
    /// by [`preprocess_fixedstructtype`]. Use `insert_cache_entry` and
229
    /// `remove_entry` to manage this cache.
230
    ///
231
    /// [`preprocess_fixedstructtype`]: FixedStructReader::preprocess_fixedstructtype
232
    pub(crate) cache_entries: FoToEntry,
233
    /// A mapping of all entries in the entire file (that pass the datetime
234
    /// filters), mapped by [`tv_pair_type`] to [`FileOffset`]. Created by
235
    /// [`preprocess_timevalues`].
236
    ///
237
    /// [`preprocess_timevalues`]: FixedStructReader::preprocess_timevalues
238
    pub(crate) map_tvpair_fo: MapTvPairToFo,
239
    pub(crate) block_use_count: BTreeMap<BlockOffset, usize>,
240
    /// The first entry found in the file, by `FileOffset`
241
    pub(crate) first_entry_fileoffset: FileOffset,
242
    /// "high watermark" of `FixedStruct` stored in `self.cache_entries`
243
    pub(crate) entries_stored_highest: usize,
244
    pub(crate) entries_out_of_order: usize,
245
    /// Internal stats - hits of `self.cache_entries` in `find_entry*` functions.
246
    pub(super) entries_hits: Count,
247
    /// Internal stats - misses of `self.cache_entries` in `find_entry*` functions.
248
    pub(super) entries_miss: Count,
249
    /// `Count` of `FixedStruct`s processed.
250
    ///
251
    /// Distinct from `self.cache_entries.len()` as that may have contents removed.
252
    pub(super) entries_processed: Count,
253
    /// First (soonest) processed [`DateTimeL`] (not necessarily printed,
254
    /// not representative of the entire file).
255
    ///
256
    /// Intended for `--summary`.
257
    ///
258
    /// [`DateTimeL`]: crate::data::datetime::DateTimeL
259
    pub(super) dt_first: DateTimeLOpt,
260
    /// Last (latest) processed [`DateTimeL`] (not necessarily printed,
261
    /// not representative of the entire file).
262
    ///
263
    /// Intended for `--summary`.
264
    ///
265
    /// [`DateTimeL`]: crate::data::datetime::DateTimeL
266
    pub(super) dt_last: DateTimeLOpt,
267
    /// `Count` of dropped `FixedStruct`.
268
    pub(super) drop_entry_ok: Count,
269
    /// `Count` of failed drop attempts of `FixedStruct`.
270
    pub(super) drop_entry_errors: Count,
271
    /// Largest `BlockOffset` of successfully dropped blocks.
272
    pub(super) blockoffset_drop_last: BlockOffset,
273
    /// testing-only tracker of successfully dropped `FixedStruct`
274
    #[cfg(test)]
275
    pub(crate) dropped_blocks: DroppedBlocks,
276
    pub(super) map_tvpair_fo_max_len: usize,
277
    /// The last [`Error`], if any, as a `String`. Set by [`set_error`].
278
    ///
279
    /// Annoyingly, cannot [Clone or Copy `Error`].
280
    ///
281
    /// [`Error`]: std::io::Error
282
    /// [Clone or Copy `Error`]: https://github.com/rust-lang/rust/issues/24135
283
    /// [`set_error`]: self::FixedStructReader#method.set_error
284
    // TRACKING: https://github.com/rust-lang/rust/issues/24135
285
    error: Option<String>,
286
}
287

288
impl fmt::Debug for FixedStructReader {
289
    fn fmt(
70✔
290
        &self,
70✔
291
        f: &mut fmt::Formatter,
70✔
292
    ) -> fmt::Result {
70✔
293
        f.debug_struct("FixedStructReader")
70✔
294
            .field("Path", &self.path())
70✔
295
            .field("Entries", &self.cache_entries.len())
70✔
296
            .field("tz_offset", &self.tz_offset)
70✔
297
            .field("dt_first", &self.dt_first)
70✔
298
            .field("dt_last", &self.dt_last)
70✔
299
            .field("Error?", &self.error)
70✔
300
            .finish()
70✔
301
    }
70✔
302
}
303

304
// TODO: [2023/04] remove redundant variable prefix name `fixedstructreader_`
305
// TODO: [2023/05] instead of having 1:1 manual copying of `FixedStructReader`
306
//       fields to `SummaryFixedStructReader` fields, just store a
307
//       `SummaryFixedStructReader` in `FixedStructReader` and update directly.
308
#[allow(non_snake_case)]
309
#[derive(Clone, Default, Eq, PartialEq, Debug)]
310
pub struct SummaryFixedStructReader {
311
    pub fixedstructreader_fixedstructtype_opt: Option<FixedStructType>,
312
    pub fixedstructreader_filetypefixedstruct_opt: Option<FileTypeFixedStruct>,
313
    pub fixedstructreader_fixedstruct_size: usize,
314
    pub fixedstructreader_high_score: Score,
315
    pub fixedstructreader_utmp_entries: Count,
316
    pub fixedstructreader_first_entry_fileoffset: FileOffset,
317
    pub fixedstructreader_entries_out_of_order: usize,
318
    pub fixedstructreader_utmp_entries_max: Count,
319
    pub fixedstructreader_utmp_entries_hit: Count,
320
    pub fixedstructreader_utmp_entries_miss: Count,
321
    pub fixedstructreader_drop_entry_ok: Count,
322
    pub fixedstructreader_drop_entry_errors: Count,
323
    /// datetime soonest seen (not necessarily reflective of entire file)
324
    pub fixedstructreader_datetime_first: DateTimeLOpt,
325
    /// datetime latest seen (not necessarily reflective of entire file)
326
    pub fixedstructreader_datetime_last: DateTimeLOpt,
327
    pub fixedstructreader_map_tvpair_fo_max_len: usize,
328
}
329

330
/// Implement the FixedStructReader.
331
impl FixedStructReader {
332
    /// Create a new `FixedStructReader`.
333
    ///
334
    /// **NOTE:** this `new()` calls [`BlockerReader.read_block`],
335
    /// dissimilar from other
336
    /// `*Readers::new()` which try to avoid calls to `read_block`.
337
    /// This means the reading may return `Done` (like if the file is empty) and
338
    /// `Done` must be reflected in the return value of `new`. Hence this
339
    /// function has a specialized return value.
340
    ///
341
    /// [`BlockerReader.read_block`]: crate::readers::blockreader::BlockReader#method.read_block
342
    pub fn new(
201✔
343
        path: FPath,
201✔
344
        filetype: FileType,
201✔
345
        blocksz: BlockSz,
201✔
346
        tz_offset: FixedOffset,
201✔
347
        dt_filter_after: DateTimeLOpt,
201✔
348
        dt_filter_before: DateTimeLOpt,
201✔
349
    ) -> ResultFixedStructReaderNewError {
201✔
350
        def1n!(
201✔
351
            "({:?}, filetype={:?}, blocksz={:?}, {:?}, {:?}, {:?})",
201✔
352
            path, filetype, blocksz, tz_offset, dt_filter_after, dt_filter_before,
353
        );
354
        let mut blockreader = match BlockReader::new(path.clone(), filetype, blocksz) {
201✔
355
            Ok(blockreader_) => blockreader_,
200✔
356
            Err(err) => {
1✔
357
                def1x!("return Err {}", err);
1✔
358
                //return Some(Result::Err(err));
359
                return ResultFixedStructReaderNew::FileErrIo(err);
1✔
360
            }
361
        };
362
        let filetype_fixedstruct = match filetype {
200✔
363
            FileType::FixedStruct { archival_type: _, fixedstruct_type: type_ } => type_,
200✔
364
            _ => {
365
                debug_panic!("Unexpected FileType: {:?}", filetype);
×
366
                return ResultFixedStructReaderNew::FileErrIo(Error::new(
×
367
                    ErrorKind::InvalidData,
×
368
                    format!("Unexpected FileType {:?}", filetype),
×
369
                ));
×
370
            }
371
        };
372

373
        const ENTRY_SZ_MIN_FSZ: FileSz = ENTRY_SZ_MIN as FileSz;
374
        if blockreader.filesz() == 0 {
200✔
375
            def1x!("return FileErrEmpty");
1✔
376
            return ResultFixedStructReaderNew::FileErrEmpty;
1✔
377
        } else if blockreader.filesz() < ENTRY_SZ_MIN_FSZ {
199✔
378
            def1x!(
1✔
379
                "return FileErrTooSmall; {} < {} (ENTRY_SZ_MIN)",
1✔
380
                blockreader.filesz(), ENTRY_SZ_MIN_FSZ
1✔
381
            );
382
            return ResultFixedStructReaderNew::FileErrTooSmall(
1✔
383
                format!(
1✔
384
                    "file size {} < {} (ENTRY_SZ_MIN), file {:?}",
1✔
385
                    blockreader.filesz(), ENTRY_SZ_MIN_FSZ, path,
1✔
386
                )
1✔
387
            );
1✔
388
        }
198✔
389

390
        // preprocess the file, pass `oneblock=false` to process
391
        // the entire file. This is because `lastlog` files are often nearly
392
        // entirely null bytes until maybe one entry near the end, so this should
393
        // search past the first block of data.
394
        let (
395
            fixedstruct_type,
190✔
396
            high_score,
190✔
397
            list_entries,
190✔
398
        ) = match FixedStructReader::preprocess_fixedstructtype(
198✔
399
            &mut blockreader, &filetype_fixedstruct, false,
198✔
400
        ) {
198✔
401
            ResultFixedStructReaderScoreFileError::FileOk(
190✔
402
                fixedstruct_type_, high_score_, list_entries_,
190✔
403
            ) => (fixedstruct_type_, high_score_, list_entries_),
190✔
404
            ResultFixedStructReaderScoreFileError::FileErrEmpty => {
×
405
                def1x!("return FileErrEmpty");
×
406
                return ResultFixedStructReaderNew::FileErrEmpty;
×
407
            }
408
            ResultFixedStructReaderScoreFileError::FileErrNoHighScore => {
8✔
409
                def1x!("return FileErrNoHighScore");
8✔
410
                return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
8✔
411
            }
412
            ResultFixedStructReaderScoreFileError::FileErrNoValidFixedStruct => {
×
413
                def1x!("return FileErrNoValidFixedStruct");
×
414
                return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
×
415
            }
416
            ResultFixedStructReaderScoreFileError::FileErrIo(err) => {
×
417
                de_err!("FixedStructReader::preprocess_fixedstructtype Error {}; file {:?}",
×
418
                        err, blockreader.path());
×
419
                def1x!("return Err {:?}", err);
×
420
                return ResultFixedStructReaderNew::FileErrIo(err);
×
421
            }
422
        };
423

424
        let (total, invalid, valid_no_filter, out_of_order, map_tvpair_fo) = 
190✔
425
            match FixedStructReader::preprocess_timevalues(
190✔
426
                &mut blockreader,
190✔
427
                fixedstruct_type,
190✔
428
                &dt_filter_after,
190✔
429
                &dt_filter_before,
190✔
430
            )
190✔
431
        {
432
            ResultTvFo::Err(err) => {
×
433
                de_err!("FixedStructReader::preprocess_timevalues Error {}; file {:?}",
×
434
                        err, blockreader.path());
×
435
                def1x!("return Err {:?}", err);
×
436
                return ResultFixedStructReaderNew::FileErrIo(err);
×
437
            }
438
            ResultTvFo::Ok(
190✔
439
                (total_, invalid_, valid_no_filter_, out_of_order_, map_tvpair_fo_)
190✔
440
            ) =>
190✔
441
                (total_, invalid_, valid_no_filter_, out_of_order_, map_tvpair_fo_),
190✔
442
        };
443
        def1o!("total: {}, invalid: {}, valid_no_filter: {}, out_of_order: {}",
190✔
444
               total, invalid, valid_no_filter, out_of_order);
445
        #[cfg(debug_assertions)]
446
        {
447
            def1o!("map_tvpair_fo has {} entries", map_tvpair_fo.len());
190✔
448
            for (_tv_pair, _fo) in map_tvpair_fo.iter() {
1,094✔
449
                def1o!("map_tvpair_fo: [tv_pair: {:?}] = fo: {}", _tv_pair, _fo);
1,094✔
450
            }
451
        }
452
        debug_assert_ge!(total, invalid);
190✔
453
        debug_assert_ge!(total, valid_no_filter);
190✔
454

455
        if map_tvpair_fo.is_empty() {
190✔
456
            if valid_no_filter > 0 {
19✔
457
                def1x!("return FileErrNoFixedStructWithinDtFilters");
19✔
458
                return ResultFixedStructReaderNew::FileErrNoFixedStructWithinDtFilters;
19✔
459
            }
×
460
            def1x!("return FileErrNoValidFixedStruct");
×
461
            return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
×
462
        }
171✔
463

464
        // set `first_entry_fileoffset` to the first entry by fileoffset
465
        let mut first_entry_fileoffset: FileOffset = blockreader.filesz();
171✔
466
        for (_tv_pair, fo) in map_tvpair_fo.iter() {
1,094✔
467
            if &first_entry_fileoffset > fo {
1,094✔
468
                first_entry_fileoffset = *fo;
201✔
469
            }
961✔
470
        }
471
        debug_assert_ne!(first_entry_fileoffset, blockreader.filesz(), "failed to update first_entry_fileoffset");
171✔
472

473
        // create a mapping of blocks to not-yet-processed entries
474
        // later on, this will be used to proactively drop blocks
475
        let mut block_use_count: BTreeMap<BlockOffset, usize> = BTreeMap::new();
171✔
476
        def1o!("block_use_count create");
171✔
477
        for (_tv_pair, fo) in map_tvpair_fo.iter() {
1,094✔
478
            let bo_beg: BlockOffset = BlockReader::block_offset_at_file_offset(*fo, blocksz);
1,094✔
479
            let fo_end: FileOffset = *fo + fixedstruct_type.size() as FileOffset;
1,094✔
480
            let bo_end: BlockOffset = BlockReader::block_offset_at_file_offset(fo_end, blocksz);
1,094✔
481
            def1o!("blocksz = {}", blocksz);
1,094✔
482
            for bo in bo_beg..bo_end + 1 {
4,337✔
483
                match block_use_count.get_mut(&bo) {
4,337✔
484
                    Some(count) => {
923✔
485
                        let count_ = *count + 1;
923✔
486
                        def1o!(
923✔
487
                            "block_use_count[{}] += 1 ({}); [{}‥{}]; total span [{}‥{})",
923✔
488
                            bo,
489
                            count_,
490
                            *fo,
491
                            fo_end,
492
                            BlockReader::file_offset_at_block_offset(bo_beg, blocksz),
923✔
493
                            BlockReader::file_offset_at_block_offset(bo_end + 1, blocksz),
923✔
494
                        );
495
                        *count = count_;
923✔
496
                    }
497
                    None => {
498
                        def1o!(
3,414✔
499
                            "block_use_count[{}] = 1; [{}‥{}]; total span [{}‥{})",
3,414✔
500
                            bo,
501
                            *fo,
502
                            fo_end,
503
                            BlockReader::file_offset_at_block_offset(bo_beg, blocksz),
3,414✔
504
                            BlockReader::file_offset_at_block_offset(bo_end + 1, blocksz),
3,414✔
505
                        );
506
                        block_use_count.insert(bo, 1);
3,414✔
507
                    }
508
                }
509
            }
510
        }
511
        #[cfg(debug_assertions)]
512
        {
513
            for (bo, count) in block_use_count.iter() {
3,414✔
514
                def1o!(
3,414✔
515
                    "block_use_count[{}] = {}; total span [{}‥{}]",
3,414✔
516
                    bo,
517
                    count,
518
                    BlockReader::file_offset_at_block_offset(*bo, blocksz),
3,414✔
519
                    BlockReader::file_offset_at_block_offset(*bo + 1, blocksz),
3,414✔
520
                );
521
            }
522
        }
523

524
        let map_max_len = map_tvpair_fo.len();
171✔
525
        // now that the `fixedstruct_type` is known, create the FixedStructReader
526
        let mut fixedstructreader = FixedStructReader {
171✔
527
            blockreader,
171✔
528
            fixedstruct_type,
171✔
529
            filetype_fixedstruct,
171✔
530
            fixedstruct_size: fixedstruct_type.size(),
171✔
531
            high_score,
171✔
532
            tz_offset,
171✔
533
            cache_entries: FoToEntry::new(),
171✔
534
            map_tvpair_fo,
171✔
535
            block_use_count,
171✔
536
            first_entry_fileoffset,
171✔
537
            entries_stored_highest: 0,
171✔
538
            entries_out_of_order: out_of_order,
171✔
539
            entries_hits: 0,
171✔
540
            entries_miss: 0,
171✔
541
            entries_processed: 0,
171✔
542
            dt_first: DateTimeLOpt::None,
171✔
543
            dt_last: DateTimeLOpt::None,
171✔
544
            drop_entry_ok: 0,
171✔
545
            drop_entry_errors: 0,
171✔
546
            blockoffset_drop_last: 0,
171✔
547
            #[cfg(test)]
171✔
548
            dropped_blocks: DroppedBlocks::new(),
171✔
549
            map_tvpair_fo_max_len: map_max_len,
171✔
550
            error: None,
171✔
551
        };
171✔
552

553
        // store the entries found and processed during `preprocess_file` into
554
        // `fixedstructreader.cache_entries`, to avoid duplicating work later on
555
        for (fo, fixedstructptr) in list_entries.into_iter() {
536✔
556
            // TODO: cost-savings: if `FixedStructTrait` had a `tv_pair` function then that time
557
            //       value could be checked against `map_tvpair_fo` *before* creating a new
558
            //       `FixedStruct`. However, the maximum number of `FixedStruct` entries
559
            //       created and then discarded will be very few so this is a marginal
560
            //       improvement.
561
            match FixedStruct::from_fixedstructptr(fo, &tz_offset, fixedstructptr) {
536✔
562
                Ok(fixedstruct) => {
536✔
563
                    if fixedstructreader
536✔
564
                        .map_tvpair_fo
536✔
565
                        .iter()
536✔
566
                        .any(|(_tv_pair, fo2)| &fo == fo2)
1,331✔
567
                    {
568
                        def1o!("insert entry at fo {}", fo);
508✔
569
                        fixedstructreader.insert_cache_entry(fixedstruct);
508✔
570
                    } else {
571
                        def1o!("skip entry at fo {}; not in map_tvpair_fo", fo);
28✔
572
                    }
573
                }
574
                Err(err) => {
×
575
                    de_err!("FixedStruct::from_fixedstructptr Error {}; file {:?}", err, fixedstructreader.path());
×
576
                    fixedstructreader.set_error(&err);
×
577
                }
×
578
            }
579
        }
580

581
        def1x!("return FileOk(FixedStructReader)");
171✔
582

583
        ResultFixedStructReaderNew::FileOk(fixedstructreader)
171✔
584
    }
201✔
585

586
    /// See [`BlockReader::blocksz`].
587
    ///
588
    /// [`BlockReader::blocksz`]: crate::readers::blockreader::BlockReader#method.blocksz
589
    #[inline(always)]
590
    pub const fn blocksz(&self) -> BlockSz {
1,039✔
591
        self.blockreader.blocksz()
1,039✔
592
    }
1,039✔
593

594
    /// See [`BlockReader::filesz`].
595
    ///
596
    /// [`BlockReader::filesz`]: crate::readers::blockreader::BlockReader#method.filesz
597
    #[inline(always)]
598
    pub const fn filesz(&self) -> FileSz {
2,296✔
599
        self.blockreader.filesz()
2,296✔
600
    }
2,296✔
601

602
    /// See [`BlockReader::filetype`].
603
    ///
604
    /// [`BlockReader::filetype`]: crate::readers::blockreader::BlockReader#method.filetype
605
    #[inline(always)]
606
    pub const fn filetype(&self) -> FileType {
93✔
607
        self.blockreader.filetype()
93✔
608
    }
93✔
609

610
    /// See [`BlockReader::path`].
611
    ///
612
    /// [`BlockReader::path`]: crate::readers::blockreader::BlockReader#method.path
613
    #[inline(always)]
614
    pub const fn path(&self) -> &FPath {
163✔
615
        self.blockreader.path()
163✔
616
    }
163✔
617

618
    /// See [`BlockReader::mtime`].
619
    ///
620
    /// [`BlockReader::mtime`]: crate::readers::blockreader::BlockReader#method.mtime
621
    pub fn mtime(&self) -> SystemTime {
70✔
622
        self.blockreader.mtime()
70✔
623
    }
70✔
624

625
    /// `Count` of `FixedStruct`s processed by this `FixedStructReader`
626
    /// (i.e. `self.entries_processed`).
627
    #[inline(always)]
628
    pub fn count_entries_processed(&self) -> Count {
1✔
629
        self.entries_processed
1✔
630
    }
1✔
631

632
    /// "_High watermark_" of `FixedStruct` stored in `self.cache_entries`.
633
    #[inline(always)]
634
    pub fn entries_stored_highest(&self) -> usize {
×
635
        self.entries_stored_highest
×
636
    }
×
637

638
    /// See [`BlockReader::block_offset_at_file_offset`].
639
    ///
640
    /// [`BlockReader::block_offset_at_file_offset`]: crate::readers::blockreader::BlockReader#method.block_offset_at_file_offset
641
    #[inline(always)]
642
    pub const fn block_offset_at_file_offset(
1✔
643
        &self,
1✔
644
        fileoffset: FileOffset,
1✔
645
    ) -> BlockOffset {
1✔
646
        BlockReader::block_offset_at_file_offset(fileoffset, self.blocksz())
1✔
647
    }
1✔
648

649
    /// See [`BlockReader::file_offset_at_block_offset`].
650
    ///
651
    /// [`BlockReader::file_offset_at_block_offset`]: crate::readers::blockreader::BlockReader#method.file_offset_at_block_offset
652
    #[inline(always)]
653
    pub const fn file_offset_at_block_offset(
1✔
654
        &self,
1✔
655
        blockoffset: BlockOffset,
1✔
656
    ) -> FileOffset {
1✔
657
        BlockReader::file_offset_at_block_offset(blockoffset, self.blocksz())
1✔
658
    }
1✔
659

660
    /// See [`BlockReader::file_offset_at_block_offset_index`].
661
    ///
662
    /// [`BlockReader::file_offset_at_block_offset_index`]: crate::readers::blockreader::BlockReader#method.file_offset_at_block_offset_index
663
    #[inline(always)]
664
    pub const fn file_offset_at_block_offset_index(
1✔
665
        &self,
1✔
666
        blockoffset: BlockOffset,
1✔
667
        blockindex: BlockIndex,
1✔
668
    ) -> FileOffset {
1✔
669
        BlockReader::file_offset_at_block_offset_index(blockoffset, self.blocksz(), blockindex)
1✔
670
    }
1✔
671

672
    /// See [`BlockReader::block_index_at_file_offset`].
673
    ///
674
    /// [`BlockReader::block_index_at_file_offset`]: crate::readers::blockreader::BlockReader#method.block_index_at_file_offset
675
    #[inline(always)]
676
    pub const fn block_index_at_file_offset(
1✔
677
        &self,
1✔
678
        fileoffset: FileOffset,
1✔
679
    ) -> BlockIndex {
1✔
680
        BlockReader::block_index_at_file_offset(fileoffset, self.blocksz())
1✔
681
    }
1✔
682

683
    /// See [`BlockReader::count_blocks`].
684
    ///
685
    /// [`BlockReader::count_blocks`]: crate::readers::blockreader::BlockReader#method.count_blocks
686
    #[inline(always)]
687
    pub const fn count_blocks(&self) -> Count {
1✔
688
        BlockReader::count_blocks(self.filesz(), self.blocksz()) as Count
1✔
689
    }
1✔
690

691
    /// See [`BlockReader::blockoffset_last`].
692
    ///
693
    /// [`BlockReader::blockoffset_last`]: crate::readers::blockreader::BlockReader#method.blockoffset_last
694
    pub const fn blockoffset_last(&self) -> BlockOffset {
1✔
695
        self.blockreader
1✔
696
            .blockoffset_last()
1✔
697
    }
1✔
698

699
    /// See [`BlockReader::fileoffset_last`].
700
    ///
701
    /// [`BlockReader::fileoffset_last`]: crate::readers::blockreader::BlockReader#method.fileoffset_last
702
    pub const fn fileoffset_last(&self) -> FileOffset {
910✔
703
        self.blockreader
910✔
704
            .fileoffset_last()
910✔
705
    }
910✔
706

707
    /// Is the passed `FileOffset` the last byte of the file?
708
    pub const fn is_fileoffset_last(
908✔
709
        &self,
908✔
710
        fileoffset: FileOffset,
908✔
711
    ) -> bool {
908✔
712
        self.fileoffset_last() == fileoffset
908✔
713
    }
908✔
714

715
    /// Is the passed `FixedStruct` the last of the file?
716
    #[inline(always)]
717
    pub fn is_last(
902✔
718
        &self,
902✔
719
        fixedstruct: &FixedStruct,
902✔
720
    ) -> bool {
902✔
721
        self.is_fileoffset_last(fixedstruct.fileoffset_end() - 1)
902✔
722
    }
902✔
723

724
    /// Return the `FileOffset` that is adjusted to the beginning offset of
725
    /// a `fixedstruct` entry.
726
    #[inline(always)]
727
    pub const fn fileoffset_to_fixedstructoffset(
1✔
728
        &self,
1✔
729
        fileoffset: FileOffset,
1✔
730
    ) -> FileOffset {
1✔
731
        (fileoffset / self.fixedstruct_size_fo()) * self.fixedstruct_size_fo()
1✔
732
    }
1✔
733

734
    /// Return the first file offset from `self.map_tvpair_fo` for the first
735
    /// entry as sorted by `tv_pair_type` (datetime); i.e. the earliest entry.
736
    /// Ties are broken by `FileOffset`.
737
    pub fn fileoffset_first(&self) -> Option<FileOffset> {
102✔
738
        match self
102✔
739
            .map_tvpair_fo
102✔
740
            .iter()
102✔
741
            .min_by_key(|(tv_pair, fo)| (*tv_pair, *fo))
971✔
742
        {
743
            Some((_tv_pair, fo_)) => Some(*fo_),
102✔
744
            None => None,
×
745
        }
746
    }
102✔
747

748
    /// The size in bytes of the `FixedStruct` entries managed by this
749
    /// `FixedStructReader`.
750
    #[inline(always)]
751
    pub const fn fixedstruct_size(&self) -> usize {
1,245✔
752
        self.fixedstruct_size
1,245✔
753
    }
1,245✔
754

755
    /// [`fixedstruct_size`] as a `FileOffset`.
756
    ///
757
    /// [`fixedstruct_size`]: self::FixedStructReader#method.fixedstruct_size
758
    #[inline(always)]
759
    pub const fn fixedstruct_size_fo(&self) -> FileOffset {
1,150✔
760
        self.fixedstruct_size() as FileOffset
1,150✔
761
    }
1,150✔
762

763
    /// The `FixedStructType` of the file.
764
    #[inline(always)]
765
    pub const fn fixedstruct_type(&self) -> FixedStructType {
673✔
766
        self.fixedstruct_type
673✔
767
    }
673✔
768

769
    /// Return all currently stored `FileOffset` in `self.cache_entries`.
770
    ///
771
    /// Only for testing.
772
    #[cfg(test)]
773
    pub fn get_fileoffsets(&self) -> Vec<FileOffset> {
1✔
774
        self.cache_entries
1✔
775
            .keys()
1✔
776
            .cloned()
1✔
777
            .collect()
1✔
778
    }
1✔
779

780
    /// store an `Error` that occurred. For later printing during `--summary`.
781
    // XXX: duplicates `SyslogProcessor.set_error`
782
    fn set_error(
×
783
        &mut self,
×
784
        error: &Error,
×
785
    ) {
×
786
        def1ñ!("{:?}", error);
×
787
        let mut error_string: String = error.kind().to_string();
×
788
        error_string.push_str(": ");
×
789
        error_string.push_str(error.kind().to_string().as_str());
×
790
        // print the error but avoid printing the same error more than once
791
        // XXX: This is somewhat a hack as it's possible the same error, with the
792
        //      the same error message, could occur more than once.
793
        //      Considered another way, this function `set_error` may get called
794
        //      too often. The responsibility for calling `set_error` is haphazard.
795
        match &self.error {
×
796
            Some(err_s) => {
×
797
                if err_s != &error_string {
×
798
                    e_err!("{}", error);
×
799
                }
×
800
            }
801
            None => {
×
802
                e_err!("{}", error);
×
803
            }
×
804
        }
805
        if let Some(ref _err) = self.error {
×
806
            de_wrn!("skip overwrite of previous Error ({:?}) with Error ({:?})", _err, error);
×
807
            return;
×
808
        }
×
809
        self.error = Some(error_string);
×
810
    }
×
811

812
    /// Store information about a single [`FixedStruct`] entry.
813
    ///
814
    /// Should only be called by `FixedStructReader::new`
815
    ///
816
    /// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
817
    fn insert_cache_entry(
508✔
818
        &mut self,
508✔
819
        entry: FixedStruct,
508✔
820
    ) {
508✔
821
        defn!("@{}", entry.fileoffset_begin());
508✔
822
        let fo_beg: FileOffset = entry.fileoffset_begin();
508✔
823
        debug_assert!(
508✔
824
            !self.cache_entries.contains_key(&fo_beg),
508✔
825
            "self.cache_entries already contains key {}",
×
826
            fo_beg
827
        );
828

829
        // update some stats and (most importantly) `self.cache_entries`
830
        self.cache_entries
508✔
831
            .insert(fo_beg, entry);
508✔
832
        self.entries_stored_highest = std::cmp::max(self.entries_stored_highest, self.cache_entries.len());
508✔
833
        self.entries_processed += 1;
508✔
834
        defo!("entries_processed = {}", self.entries_processed);
508✔
835

836
        defx!();
508✔
837
    }
508✔
838

839
    /// Update the statistic `DateTimeL` of
840
    /// `self.dt_first` and `self.dt_last`
841
    fn dt_first_last_update(
1,033✔
842
        &mut self,
1,033✔
843
        datetime: &DateTimeL,
1,033✔
844
    ) {
1,033✔
845
        defñ!("({:?})", datetime);
1,033✔
846
        // TODO: cost-savings: the `dt_first` and `dt_last` are only for `--summary`,
847
        //       no need to always copy datetimes.
848
        //       Would be good to only run this when `if self.do_summary {...}`
849
        match self.dt_first {
1,033✔
850
            Some(dt_first_) => {
872✔
851
                if &dt_first_ > datetime {
872✔
852
                    self.dt_first = Some(*datetime);
×
853
                }
872✔
854
            }
855
            None => {
161✔
856
                self.dt_first = Some(*datetime);
161✔
857
            }
161✔
858
        }
859
        match self.dt_last {
1,033✔
860
            Some(dt_last_) => {
872✔
861
                if &dt_last_ < datetime {
872✔
862
                    self.dt_last = Some(*datetime);
871✔
863
                }
871✔
864
            }
865
            None => {
161✔
866
                self.dt_last = Some(*datetime);
161✔
867
            }
161✔
868
        }
869
    }
1,033✔
870

871
    /// Proactively `drop` the [`Block`s] associated with the
872
    /// passed [`FixedStruct`]. Return count of dropped entries (0 or 1).
873
    ///
874
    /// _The caller must know what they are doing!_
875
    ///
876
    /// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
877
    /// [`Block`s]: crate::readers::blockreader::Block
878
    /// [`FileOffset`]: crate::common::FileOffset
879
    fn drop_entry(
1,033✔
880
        &mut self,
1,033✔
881
        fixedstruct: &FixedStruct,
1,033✔
882
    ) -> usize {
1,033✔
883
        let bsz: BlockSz = self.blocksz();
1,033✔
884
        defn!(
1,033✔
885
            "(fixedstruct@{}); offsets [{}‥{}), blocks [{}‥{}]",
1,033✔
886
            fixedstruct.fileoffset_begin(),
1,033✔
887
            fixedstruct.fileoffset_begin(),
1,033✔
888
            fixedstruct.fileoffset_end(),
1,033✔
889
            fixedstruct.blockoffset_begin(bsz),
1,033✔
890
            fixedstruct.blockoffset_end(bsz),
1,033✔
891
        );
892
        let mut dropped_ok: usize = 0;
1,033✔
893
        let mut dropped_err: usize = 0;
1,033✔
894
        let mut bo_at: BlockOffset = fixedstruct.blockoffset_begin(bsz);
1,033✔
895
        let bo_end: BlockOffset = fixedstruct.blockoffset_end(bsz);
1,033✔
896
        debug_assert_le!(bo_at, bo_end);
1,033✔
897
        while bo_at <= bo_end {
4,819✔
898
            defo!("block_use_count.get_mut({})", bo_at);
3,786✔
899
            match self.block_use_count.get_mut(&bo_at) {
3,786✔
900
                Some(count) => {
3,782✔
901
                    if *count <= 1 {
3,782✔
902
                        defo!(
2,876✔
903
                            "block_use_count[{}] found; count=={}; total span [{}‥{})",
2,876✔
904
                            bo_at, count,
905
                            BlockReader::file_offset_at_block_offset(bo_at, bsz),
2,876✔
906
                            BlockReader::file_offset_at_block_offset(bo_end + 1, bsz),
2,876✔
907
                        );
908
                        if self
2,876✔
909
                            .blockreader
2,876✔
910
                            .drop_block(bo_at)
2,876✔
911
                        {
912
                            defo!(
2,873✔
913
                                "dropped block {}; total span [{}‥{})",
2,873✔
914
                                bo_at,
915
                                BlockReader::file_offset_at_block_offset(bo_at, bsz),
2,873✔
916
                                BlockReader::file_offset_at_block_offset(bo_end + 1, bsz),
2,873✔
917
                            );
918
                            // the largest blockoffset that has been dropped should also
919
                            // imply that all prior blockoffsets have been dropped
920
                            self.blockoffset_drop_last = std::cmp::max(bo_at, self.blockoffset_drop_last);
2,873✔
921
                            self.block_use_count.remove(&bo_at);
2,873✔
922
                            #[cfg(test)]
923
                            self.dropped_blocks.push_back(bo_at);
2,803✔
924
                            dropped_ok += 1;
2,873✔
925
                        } else {
926
                            defo!("failed to drop block {}", bo_at);
3✔
927
                            dropped_err += 1;
3✔
928
                        }
929
                    } else {
930
                        *count -= 1;
906✔
931
                        defo!("block_use_count[{}] found; count-=1=={}", bo_at, *count);
906✔
932
                    }
933
                }
934
                None => {
935
                    defo!("block_use_count[{}] not found", bo_at);
4✔
936
                }
937
            }
938
            bo_at += 1;
3,786✔
939
        }
940
        if dropped_ok > 0 {
1,033✔
941
            self.drop_entry_ok += 1;
171✔
942
        }
931✔
943
        if dropped_err > 0 {
1,033✔
944
            self.drop_entry_errors += 1;
2✔
945
        }
1,031✔
946
        defx!("return {}", dropped_ok);
1,033✔
947

948
        dropped_ok
1,033✔
949
    }
1,033✔
950

951
    /// Check the internal storage `self.cache_entries`.
952
    /// Remove the entry and return it if found.
953
    #[inline(always)]
954
    fn remove_cache_entry(
1,033✔
955
        &mut self,
1,033✔
956
        fileoffset: FileOffset,
1,033✔
957
    ) -> Option<FixedStruct> {
1,033✔
958
        match self.cache_entries.remove(&fileoffset) {
1,033✔
959
            Some(fixedstruct) => {
454✔
960
                defñ!("({}): found in store", fileoffset);
454✔
961
                self.entries_hits += 1;
454✔
962

963
                Some(fixedstruct)
454✔
964
            }
965
            None => {
966
                defñ!("({}): not found in store", fileoffset);
579✔
967
                self.entries_miss += 1;
579✔
968

969
                None
579✔
970
            }
971
        }
972
    }
1,033✔
973

974
    /// Process entries for the file managed by the `BlockReader`.
975
    /// Find the entry with the highest "score" as judged by `score_fixedstruct`.
976
    ///
977
    /// Returns the highest scored `FixedStructType`, that highest score,
978
    /// and any processed [`FixedStruct`] entries (referenced by a
979
    /// [`FixedStructDynPtr`]) in a list.
980
    ///
981
    /// Each list entry is a tuple of the
982
    /// the entries `FileOffset` and the `FixedStructDynPtr`.
983
    /// The entries will presumably be stored in the
984
    /// `FixedStructReader`'s `cache_entries`.
985
    pub fn score_file(
198✔
986
        blockreader: &mut BlockReader,
198✔
987
        oneblock: bool,
198✔
988
        types_to_bonus: FixedStructTypeSet,
198✔
989
    ) -> ResultFixedStructReaderScoreFileError {
198✔
990
        def1n!("(oneblock={}, types_to_bonus len {})", oneblock, types_to_bonus.len());
198✔
991
        #[cfg(debug_assertions)]
992
        {
993
            for (fixedstructtype, bonus) in types_to_bonus.iter() {
771✔
994
                def1o!("types_to_bonus: ({:<30?}, {:2}) size {}", fixedstructtype, bonus, fixedstructtype.size(),);
771✔
995
            }
996
        }
997
        // allocate largest possible buffer needed on the stack
998
        let mut buffer: [u8; ENTRY_SZ_MAX] = [0; ENTRY_SZ_MAX];
198✔
999
        // only score this number of entries, i.e. don't walk the
1000
        // entire file scoring all entries
1001
        #[cfg(not(test))]
1002
        const COUNT_FOUND_ENTRIES_MAX: usize = 5;
1003
        #[cfg(test)]
1004
        const COUNT_FOUND_ENTRIES_MAX: usize = 2;
1005
        let mut _count_total: usize = 0;
198✔
1006
        let mut highest_score: Score = 0;
198✔
1007
        let mut highest_score_type: Option<FixedStructType> = None;
198✔
1008
        let mut highest_score_entries = ListFileOffsetFixedStructPtr::new();
198✔
1009

1010
        for (fixedstructtype, bonus) in types_to_bonus.into_iter() {
771✔
1011
            let mut _count_loop: usize = 0;
771✔
1012
            let mut count_found_entries: usize = 0;
771✔
1013
            let mut high_score: Score = 0;
771✔
1014
            let mut fo: FileOffset = 0;
771✔
1015
            let mut found_entries = ListFileOffsetFixedStructPtr::new();
771✔
1016

1017
            loop {
1018
                if count_found_entries >= COUNT_FOUND_ENTRIES_MAX {
4,192✔
1019
                    def1o!("count_found_entries {} >= COUNT_FOUND_ENTRIES_MAX {}", count_found_entries, COUNT_FOUND_ENTRIES_MAX);
724✔
1020
                    break;
724✔
1021
                }
3,468✔
1022
                _count_total += 1;
3,468✔
1023
                _count_loop += 1;
3,468✔
1024
                let utmp_sz: usize = fixedstructtype.size();
3,468✔
1025
                let fo_end = fo + utmp_sz as FileOffset;
3,468✔
1026
                def1o!(
3,468✔
1027
                    "loop try {} (total {}), fixedstructtype {:?}, zero the buffer (size {}), looking at fileoffset {}‥{} (0x{:08X}‥0x{:08X})",
3,468✔
1028
                    _count_loop, _count_total, fixedstructtype, buffer.len(), fo, fo_end, fo, fo_end
3,468✔
1029
                );
1030
                // zero out the buffer
1031
                // XXX: not strictly necessary to zero buffer but it helps humans
1032
                //      manually reviewing debug logs
1033
                // this compiles down to a single `memset` call
1034
                // See https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,selection:(endColumn:1,endLineNumber:5,positionColumn:1,positionLineNumber:5,selectionStartColumn:1,selectionStartLineNumber:5,startColumn:1,startLineNumber:5),source:'pub+fn+foo()+%7B%0A++++const+ENTRY_SZ_MAX:+usize+%3D+400%3B%0A++++let+mut+buffer:+%5Bu8%3B+ENTRY_SZ_MAX%5D+%3D+%5B0%3B+ENTRY_SZ_MAX%5D%3B%0A++++buffer.iter_mut().for_each(%7Cm%7C+*m+%3D+0)%3B%0A%0A++++std::hint::black_box(buffer)%3B%0A%7D'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:41.18316477421653,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:r1750,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'1',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,libs:!(),options:'-O',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+rustc+1.75.0+(Editor+%231)',t:'0')),k:42.788718063415104,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+rustc+1.75.0+(Compiler+%231)',t:'0')),k:16.028117162368364,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
1035
                // See https://godbolt.org/z/KcxW9hWYb
1036
                buffer.iter_mut().for_each(|m| *m = 0);
3,468✔
1037
                // read data into buffer
1038
                let buffer_read: usize = match blockreader.read_data_to_buffer(fo, fo_end, oneblock, &mut buffer) {
3,468✔
1039
                    ResultReadDataToBuffer::Found(buffer_read) => buffer_read,
3,421✔
1040
                    ResultReadDataToBuffer::Err(err) => {
×
1041
                        def1x!("return Err");
×
1042
                        return ResultFixedStructReaderScoreFileError::FileErrIo(err);
×
1043
                    }
1044
                    ResultReadDataToBuffer::Done => {
47✔
1045
                        // reached end of block (if `oneblock` is `true`) or end of file
1046
                        break;
47✔
1047
                    }
1048
                };
1049
                if buffer_read < utmp_sz {
3,421✔
1050
                    def1o!(
×
1051
                        "read_data_to_buffer read bytes {} < {} requested fixedstruct size bytes; break",
×
1052
                        buffer_read,
1053
                        utmp_sz,
1054
                    );
1055
                    break;
×
1056
                }
3,421✔
1057
                // advance the file offset for the next loop
1058
                let fo2 = fo;
3,421✔
1059
                fo += utmp_sz as FileOffset;
3,421✔
1060
                // grab the slice of interest
1061
                let slice_ = &buffer[..buffer_read];
3,421✔
1062
                // convert buffer to fixedstruct
1063
                let fixedstructptr: FixedStructDynPtr = match buffer_to_fixedstructptr(slice_, fixedstructtype) {
3,421✔
1064
                    Some(val) => val,
2,311✔
1065
                    None => {
1066
                        def1o!(
1,110✔
1067
                            "buffer_to_fixedstructptr(buf len {}, {:?}) returned None; continue",
1,110✔
1068
                            buffer.len(),
1,110✔
1069
                            fixedstructtype,
1070
                        );
1071
                        continue;
1,110✔
1072
                    }
1073
                };
1074
                count_found_entries += 1;
2,311✔
1075
                // score the newly create fixedstruct
1076
                let score: Score = FixedStruct::score_fixedstruct(&fixedstructptr, bonus);
2,311✔
1077
                def1o!("score {} for entry type {:?} @[{}‥{}]", score, fixedstructptr.fixedstruct_type(), fo2, fo_end);
2,311✔
1078
                // update the high score
1079
                let _fs_type: FixedStructType = fixedstructptr.fixedstruct_type();
2,311✔
1080
                found_entries.push_back((fo2, fixedstructptr));
2,311✔
1081
                if score <= high_score {
2,311✔
1082
                    def1o!("score {} ({:?}) not higher than high score {}", score, _fs_type, high_score,);
2,092✔
1083
                    // score is not higher than high score so continue
1084
                    continue;
2,092✔
1085
                }
219✔
1086
                // there is a new high score for this type
1087
                def1o!("new high score {} for entry type {:?} @[{}‥{}]", score, _fs_type, fo2, fo_end);
219✔
1088
                high_score = score;
219✔
1089
            }
1090
            // finished with that fixedstructtype
1091
            // so check if it's high score beat any previous high score of a different fixedstructtype
1092
            if high_score > highest_score {
771✔
1093
                // a new high score was found for a different type so throw away
1094
                // linked lists of entries for the previous type
1095
                match highest_score_type {
199✔
1096
                    None => {
1097
                        def1o!(
190✔
1098
                            "new highest score {} entry type {:?} with {} entries",
190✔
1099
                            high_score, fixedstructtype, found_entries.len(),
190✔
1100
                        );
1101
                    }
1102
                    Some(_highest_score_type) => {
9✔
1103
                        def1o!(
9✔
1104
                            "new highest score {} entry type {:?} with {} entries; replaces old high score {} entry type {:?} with {} entries (entries dropped)",
9✔
1105
                            high_score, fixedstructtype, found_entries.len(),
9✔
1106
                            highest_score, _highest_score_type, highest_score_entries.len(),
9✔
1107
                        );
1108
                    }
1109
                }
1110
                highest_score = high_score;
199✔
1111
                highest_score_type = Some(fixedstructtype);
199✔
1112
                highest_score_entries = found_entries;
199✔
1113
            } else {
1114
                def1o!(
572✔
1115
                    "no new highest score: score {} entry type {:?} with {} entries. old high score remains: score {} entry type {:?} with {} entries",
572✔
1116
                    high_score, fixedstructtype, found_entries.len(),
572✔
1117
                    highest_score, highest_score_type, highest_score_entries.len(),
572✔
1118
                );
1119
            }
1120
        }
1121

1122
        match highest_score_type {
198✔
1123
            None => {
1124
                def1x!("return Err {:?}", ResultFixedStructReaderScoreFileError::FileErrNoHighScore);
8✔
1125
                return ResultFixedStructReaderScoreFileError::FileErrNoHighScore;
8✔
1126
            }
1127
            Some(highest_score_type) => {
190✔
1128
                def1x!("return Ok(({:?}, {}, found_entries))", highest_score_type, highest_score);
190✔
1129

1130
                ResultFixedStructReaderScoreFileError::FileOk(highest_score_type, highest_score, highest_score_entries)
190✔
1131
            }
1132
        }
1133
    }
198✔
1134

1135
    /// Determine the `FixedStructType` based on the file size and data.
1136
    ///
1137
    /// 1. Makes best guess about file structure based on size by calling
1138
    ///    `filesz_to_types`
1139
    /// 2. Searches for a valid struct within the first block of the file (if
1140
    ///    `oneblock` is `true`, else searches all available blocks).
1141
    /// 3. Creates a [`FixedStruct`] from the found struct.
1142
    ///
1143
    /// Call this before calling `process_entry_at`.
1144
    ///
1145
    /// [OpenBSD file `w.c`] processes `/var/log/utmp`. Reviewing the code you
1146
    /// get some idea of how the file is determined to be valid.
1147
    ///
1148
    /// [OpenBSD file `w.c`]: https://github.com/openbsd/src/blob/20248fc4cbb7c0efca41a8aafd40db7747023515/usr.bin/w/w.c
1149
    pub(crate) fn preprocess_fixedstructtype(
198✔
1150
        blockreader: &mut BlockReader,
198✔
1151
        filetype_fixedstruct: &FileTypeFixedStruct,
198✔
1152
        oneblock: bool,
198✔
1153
    ) -> ResultFixedStructReaderScoreFileError {
198✔
1154
        def1n!("({:?}, oneblock={})", filetype_fixedstruct, oneblock);
198✔
1155

1156
        // short-circuit special case of empty file
1157
        if blockreader.filesz() == 0 {
198✔
1158
            def1x!("empty file; return FileErrEmpty");
×
1159
            return ResultFixedStructReaderScoreFileError::FileErrEmpty;
×
1160
        }
198✔
1161

1162
        let types_to_bonus: FixedStructTypeSet = match filesz_to_types(
198✔
1163
            blockreader.filesz(),
198✔
1164
            filetype_fixedstruct,
198✔
1165
        ) {
198✔
1166
            Some(set) => set,
198✔
1167
            None => {
1168
                de_wrn!("FixedStructReader::filesz_to_types({}) failed; file {:?}",
×
1169
                        blockreader.filesz(), blockreader.path());
×
1170
                def1x!("filesz_to_types returned None; return FileErrNoValidFixedStruct");
×
1171
                return ResultFixedStructReaderScoreFileError::FileErrNoValidFixedStruct;
×
1172
            }
1173
        };
1174
        def1o!("filesz_to_types returned {} types: {:?}", types_to_bonus.len(), types_to_bonus);
198✔
1175

1176
        let ret = FixedStructReader::score_file(blockreader, oneblock, types_to_bonus);
198✔
1177
        def1x!("score_file returned {:?}", ret);
198✔
1178

1179
        ret
198✔
1180
    }
198✔
1181

1182
    /// Jump to each entry offset, convert the raw bytes to a `tv_pair_type`.
1183
    /// If the value is within the passed filters than save the value and the
1184
    /// file offset of the entry.
1185
    /// Return a count of out of order entries, and map of filtered tv_pair to
1186
    /// fileoffsets. The fileoffsets in the map are the fixedstruct offsets
1187
    /// (not timevalue offsets).
1188
    pub(crate) fn preprocess_timevalues(
190✔
1189
        blockreader: &mut BlockReader,
190✔
1190
        fixedstruct_type: FixedStructType,
190✔
1191
        dt_filter_after: &DateTimeLOpt,
190✔
1192
        dt_filter_before: &DateTimeLOpt,
190✔
1193
    ) -> ResultTvFo {
190✔
1194
        defn!();
190✔
1195
        // allocate largest possible buffer needed on the stack
1196
        let mut buffer: [u8; TIMEVAL_SZ_MAX] = [0; TIMEVAL_SZ_MAX];
190✔
1197
        // map of time values to file offsets
1198
        let mut map_tv_pair_fo: MapTvPairToFo = MapTvPairToFo::new();
190✔
1199
        // count of out of order entries
1200
        let mut out_of_order: usize = 0;
190✔
1201
        // valid fixedstruct but does not pass the time value filters
1202
        let mut valid_no_pass_filter: usize = 0;
190✔
1203
        // null fixedstruct or non-sense time values
1204
        let mut invalid: usize = 0;
190✔
1205
        // total number of entries processed
1206
        let mut total_entries: usize = 0;
190✔
1207

1208
        let tv_filter_after: Option<tv_pair_type> = match dt_filter_after {
190✔
1209
            Some(dt) => Some(convert_datetime_tvpair(dt)),
60✔
1210
            None => None,
130✔
1211
        };
1212
        defo!("tv_filter_after: {:?}", tv_filter_after);
190✔
1213
        let tv_filter_before: Option<tv_pair_type> = match dt_filter_before {
190✔
1214
            Some(dt) => Some(convert_datetime_tvpair(dt)),
34✔
1215
            None => None,
156✔
1216
        };
1217
        defo!("tv_filter_before: {:?}", tv_filter_before);
190✔
1218

1219
        // 1. get offsets
1220
        let entry_sz: FileOffset = fixedstruct_type.size() as FileOffset;
190✔
1221
        debug_assert_eq!(blockreader.filesz() % entry_sz, 0, "file not a multiple of entry size {}", entry_sz);
190✔
1222
        let tv_sz: usize = fixedstruct_type.size_tv();
190✔
1223
        let tv_offset: usize = fixedstruct_type.offset_tv();
190✔
1224
        let slice_: &mut [u8] = &mut buffer[..tv_sz];
190✔
1225
        let mut fo: FileOffset = 0;
190✔
1226
        let mut tv_pair_prev: Option<tv_pair_type> = None;
190✔
1227
        loop {
1228
            // 2. jump to each offset, grab datetime bytes,
1229
            let beg: FileOffset = fo + tv_offset as FileOffset;
1,367✔
1230
            let end: FileOffset = beg + tv_sz as FileOffset;
1,367✔
1231
            match blockreader.read_data_to_buffer(beg, end, false, slice_) {
1,367✔
1232
                ResultReadDataToBuffer::Found(_readn) => {
1,177✔
1233
                    defo!("read {} bytes at fileoffset {}", _readn, beg);
1,177✔
1234
                    debug_assert_eq!(
1,177✔
1235
                        _readn, tv_sz,
1236
                        "read {} bytes, expected {} bytes (size of a time value)",
×
1237
                        _readn, tv_sz,
1238
                    );
1239
                }
1240
                ResultReadDataToBuffer::Err(err) => {
×
1241
                    defx!("return Err");
×
1242
                    return ResultTvFo::Err(err);
×
1243
                }
1244
                ResultReadDataToBuffer::Done => {
190✔
1245
                    defo!("return Done");
190✔
1246
                    break;
190✔
1247
                }
1248
            }
1249
            // 3. convert bytes to tv_sec, tv_usec
1250
            let tv_pair: tv_pair_type = match fixedstruct_type.tv_pair_from_buffer(slice_) {
1,177✔
1251
                Some(pair) => pair,
1,177✔
1252
                None => {
1253
                    de_err!("invalid entry at fileoffset {}", fo);
×
1254
                    defo!("invalid entry at fileoffset {}", fo);
×
1255
                    fo += entry_sz;
×
1256
                    invalid += 1;
×
1257
                    continue;
×
1258
                }
1259
            };
1260
            defo!("tv_pair: {:?}", tv_pair);
1,177✔
1261
            if tv_pair == tv_pair_type(0, 0) {
1,177✔
1262
                defo!("tv_pair is (0, 0); continue");
×
1263
                fo += entry_sz;
×
1264
                continue;
×
1265
            }
1,177✔
1266
            match tv_pair_prev {
1,177✔
1267
                Some(tv_pair_prev) => {
987✔
1268
                    if tv_pair < tv_pair_prev {
987✔
1269
                        out_of_order += 1;
70✔
1270
                        defo!(
70✔
1271
                            "out_of_order = {}; tv_pair = {:?}, tv_pair_prev = {:?}",
70✔
1272
                            out_of_order,
1273
                            tv_pair,
1274
                            tv_pair_prev,
1275
                        );
1276
                    }
917✔
1277
                }
1278
                None => {}
190✔
1279
            }
1280
            tv_pair_prev = Some(tv_pair);
1,177✔
1281
            total_entries += 1;
1,177✔
1282
            // 4. compare to time value filters
1283
            if let Some(tv_filter) = tv_filter_after {
1,177✔
1284
                if tv_pair < tv_filter {
150✔
1285
                    defo!("tv_pair {:?} < {:?} tv_filter_after; continue", tv_pair, tv_filter);
61✔
1286
                    fo += entry_sz;
61✔
1287
                    valid_no_pass_filter += 1;
61✔
1288
                    continue;
61✔
1289
                }
89✔
1290
            }
1,027✔
1291
            if let Some(tv_filter) = tv_filter_before {
1,116✔
1292
                if tv_pair > tv_filter {
49✔
1293
                    defo!("tv_pair {:?} > {:?} tv_filter_before; continue", tv_pair, tv_filter);
22✔
1294
                    fo += entry_sz;
22✔
1295
                    valid_no_pass_filter += 1;
22✔
1296
                    // continue to check _all_ entries as the entries may not be
1297
                    // in chronological order
1298
                    continue;
22✔
1299
                }
27✔
1300
            }
1,067✔
1301
            // 5. save entries that pass the time value filters
1302
            defo!("tv_pair {:?} @{} passes time value filters", tv_pair, fo);
1,094✔
1303
            map_tv_pair_fo.insert(tv_pair, fo);
1,094✔
1304

1305
            fo += entry_sz;
1,094✔
1306
        }
1307
        // 6. return list of valid entries
1308
        defx!("map_tv_pair_fo len {}", map_tv_pair_fo.len());
190✔
1309

1310
        ResultTvFo::Ok((total_entries, invalid, valid_no_pass_filter, out_of_order, map_tv_pair_fo))
190✔
1311
    }
190✔
1312

1313
    /// Process the data at FileOffset `fo`. Transform it into a `FixedStruct`
1314
    /// using [`FixedStruct::new`].
1315
    /// But before that, check private `self.cache_entries`
1316
    /// in case the data at the fileoffset was already processed (transformed)
1317
    /// during `FixedStructReader::new`.
1318
    ///
1319
    /// Let the caller pass a `buffer` to avoid this function having allocate.
1320
    ///
1321
    /// This function does the bulk of file processing after the
1322
    /// `FixedStructReader` has been initialized during
1323
    /// [`FixedStructReader::new`].
1324
    pub fn process_entry_at(
1,147✔
1325
        &mut self,
1,147✔
1326
        fo: FileOffset,
1,147✔
1327
        buffer: &mut [u8],
1,147✔
1328
    ) -> ResultFindFixedStruct {
1,147✔
1329
        defn!("({})", fo);
1,147✔
1330

1331
        let sz: FileOffset = self.fixedstruct_size_fo();
1,147✔
1332
        debug_assert_eq!(fo % sz, 0, "fileoffset {} not multiple of {}", fo, sz,);
1,147✔
1333
        let fileoffset: FileOffset = fo - (fo % sz);
1,147✔
1334

1335
        if fileoffset >= self.filesz() {
1,147✔
1336
            defx!("return ResultFindFixedStruct::Done; fileoffset {} >= filesz {}", fileoffset, self.filesz());
114✔
1337
            return ResultFindFixedStruct::Done;
114✔
1338
        }
1,033✔
1339

1340
        // The `map_tvpair_fo` is the oracle listing of entries ordered by
1341
        // `tv_pair` (it was  fully created during `preprocess_timevalues`).
1342
        // Search `map_tvpair_fo` for the passed `fo`, then return the
1343
        // fileoffset of the entry *after that* which will be returned in `Found`.
1344
        // If no next fileoffset is found it means `map_tvpair_fo` is empty.
1345
        // In that case, the `fo_next` will be the value of `filesz()` and the
1346
        // next call to `process_entry_at` will return `Done`.
1347
        let fo_next: FileOffset = {
1,033✔
1348
            let mut fo_next_: FileOffset = self.filesz();
1,033✔
1349
            let mut next_pair: bool = false;
1,033✔
1350
            let mut tv_pair_at_opt: Option<tv_pair_type> = None;
1,033✔
1351
            // TODO: is there a rustic iterator way to
1352
            //       "find something and return the next thing"?
1353
            for (tv_pair_at, fo_at) in self.map_tvpair_fo.iter() {
1,944✔
1354
                if next_pair {
1,944✔
1355
                    defo!("set fo_next = {}", fo_at);
887✔
1356
                    fo_next_ = *fo_at;
887✔
1357
                    break;
887✔
1358
                }
1,057✔
1359
                if &fileoffset == fo_at {
1,057✔
1360
                    defo!("found fileoffset {} with key {:?} in map_tvpair_fo", fileoffset, tv_pair_at,);
1,025✔
1361
                    tv_pair_at_opt = Some(*tv_pair_at);
1,025✔
1362
                    next_pair = true;
1,025✔
1363
                }
32✔
1364
            }
1365
            // remove the `tv_pair` from `map_tvpair_fo`
1366
            match tv_pair_at_opt {
1,033✔
1367
                Some(tv_pair_at) => {
1,025✔
1368
                    self.map_tvpair_fo
1,025✔
1369
                        .remove(&tv_pair_at);
1,025✔
1370
                    defo!("remove tv_pair {:?}; map_tvpair_fo size {}", tv_pair_at, self.map_tvpair_fo.len());
1,025✔
1371
                }
1372
                None => {
1373
                    defo!("no map_tvpair_fo found!");
8✔
1374
                }
1375
            }
1376

1377
            fo_next_
1,033✔
1378
        };
1379
        defo!("fo_next = {}", fo_next);
1,033✔
1380

1381
        // check if the entry is already stored
1382
        if let Some(fixedstruct) = self.remove_cache_entry(fileoffset) {
1,033✔
1383
            self.dt_first_last_update(fixedstruct.dt());
454✔
1384
            // try to drop blocks associated with the entry
1385
            self.drop_entry(&fixedstruct);
454✔
1386
            defx!("remove_cache_entry found fixedstruct at fileoffset {}; return Found({}, …)", fileoffset, fo_next,);
454✔
1387
            return ResultFindFixedStruct::Found((fo_next, fixedstruct));
454✔
1388
        }
579✔
1389

1390
        // the entry was not in the cache so read the raw bytes from the file
1391
        // and transform them into a `FixedStruct`
1392

1393
        // check the buffer size
1394
        if buffer.len() < sz as usize {
579✔
1395
            defx!("return ResultFindFixedStruct::Err");
×
1396
            return ResultFindFixedStruct::Err((
×
1397
                None,
×
1398
                Error::new(
×
1399
                    ErrorKind::InvalidData,
×
1400
                    format!(
×
1401
                        "buffer size {} less than fixedstruct size {} at fileoffset {}, file {:?}",
×
1402
                        buffer.len(), sz, fileoffset, self.path(),
×
1403
                    ),
×
1404
                ),
×
1405
            ));
×
1406
        }
579✔
1407

1408
        // zero out the slice
1409
        defo!("zero buffer[‥{}]", sz);
579✔
1410
        let slice_: &mut [u8] = &mut buffer[..sz as usize];
579✔
1411
        slice_.iter_mut().for_each(|m| *m = 0);
579✔
1412

1413
        // read raw bytes into the slice
1414
        let _readn = match self
579✔
1415
            .blockreader
579✔
1416
            .read_data_to_buffer(fileoffset, fileoffset + sz, false, slice_)
579✔
1417
        {
1418
            ResultReadDataToBuffer::Found(val) => val,
579✔
1419
            ResultReadDataToBuffer::Done => {
×
1420
                defx!("return ResultFindFixedStruct::Done; read_data_to_buffer returned Done");
×
1421
                return ResultFindFixedStruct::Done;
×
1422
            }
1423
            ResultReadDataToBuffer::Err(err) => {
×
1424
                self.set_error(&err);
×
1425
                defx!("return ResultFindFixedStruct::Err({:?})", err);
×
1426
                // an error from `blockreader.read_data_to_buffer` is unlikely to improve
1427
                // with a retry so return `None` signifying no more processing of the file
1428
                return ResultFindFixedStruct::Err((None, err));
×
1429
            }
1430
        };
1431
        debug_assert_eq!(_readn, sz as usize, "read {} bytes, expected {} bytes", _readn, sz);
579✔
1432

1433
        // create a FixedStruct from the slice
1434
        let fs: FixedStruct = match FixedStruct::new(
579✔
1435
            fileoffset,
579✔
1436
            &self.tz_offset,
579✔
1437
            slice_,
579✔
1438
            self.fixedstruct_type(),
579✔
1439
        ) {
579✔
1440
            Ok(val) => val,
579✔
1441
            Err(err) => {
×
1442
                defx!("return ResultFindFixedStruct::Done; FixedStruct::new returned Err({:?})", err);
×
1443
                return ResultFindFixedStruct::Err((Some(fo_next), err));
×
1444
            }
1445
        };
1446
        // update various statistics/counters
1447
        self.entries_processed += 1;
579✔
1448
        defo!("entries_processed = {}", self.entries_processed);
579✔
1449
        self.dt_first_last_update(fs.dt());
579✔
1450
        // try to drop blocks associated with the entry
1451
        self.drop_entry(&fs);
579✔
1452

1453
        defx!("return ResultFindFixedStruct::Found((fo_next={}, …))", fo_next);
579✔
1454

1455
        ResultFindFixedStruct::Found((fo_next, fs))
579✔
1456
    }
1,147✔
1457

1458
    /// Wrapper function for call to [`datetime::dt_after_or_before`] using the
1459
    /// [`FixedStruct::dt`] of the `entry`.
1460
    ///
1461
    /// [`datetime::dt_after_or_before`]: crate::data::datetime::dt_after_or_before
1462
    /// [`FixedStruct::dt`]: crate::data::fixedstruct::FixedStruct::dt
1463
    pub fn entry_dt_after_or_before(
×
1464
        entry: &FixedStruct,
×
1465
        dt_filter: &DateTimeLOpt,
×
1466
    ) -> Result_Filter_DateTime1 {
×
1467
        defñ!("({:?})", dt_filter);
×
1468

1469
        dt_after_or_before(entry.dt(), dt_filter)
×
1470
    }
×
1471

1472
    /// Wrapper function for call to [`datetime::dt_pass_filters`] using the
1473
    /// [`FixedStruct::dt`] of the `entry`.
1474
    ///
1475
    /// [`datetime::dt_pass_filters`]: crate::data::datetime::dt_pass_filters
1476
    /// [`FixedStruct::dt`]: crate::data::fixedstruct::FixedStruct::dt
1477
    #[inline(always)]
1478
    pub fn entry_pass_filters(
×
1479
        entry: &FixedStruct,
×
1480
        dt_filter_after: &DateTimeLOpt,
×
1481
        dt_filter_before: &DateTimeLOpt,
×
1482
    ) -> Result_Filter_DateTime2 {
×
1483
        defn!("({:?}, {:?})", dt_filter_after, dt_filter_before);
×
1484

1485
        let result: Result_Filter_DateTime2 = dt_pass_filters(
×
1486
            entry.dt(),
×
1487
            dt_filter_after,
×
1488
            dt_filter_before
×
1489
        );
1490
        defx!("(…) return {:?};", result);
×
1491

1492
        result
×
1493
    }
×
1494

1495
    /// Return an up-to-date [`SummaryFixedStructReader`] instance for this
1496
    /// `FixedStructReader`.
1497
    ///
1498
    /// [`SummaryFixedStructReader`]: SummaryFixedStructReader
1499
    #[allow(non_snake_case)]
1500
    pub fn summary(&self) -> SummaryFixedStructReader {
94✔
1501
        let fixedstructreader_fixedstructtype_opt = Some(self.fixedstruct_type());
94✔
1502
        let fixedstructreader_filetypefixedstruct_opt = Some(self.filetype_fixedstruct);
94✔
1503
        let fixedstructreader_high_score: Score = self.high_score;
94✔
1504
        let fixedstructreader_utmp_entries: Count = self.entries_processed;
94✔
1505
        let fixedstructreader_first_entry_fileoffset: FileOffset = self.first_entry_fileoffset;
94✔
1506
        let fixedstructreader_entries_out_of_order: usize = self.entries_out_of_order;
94✔
1507
        let fixedstructreader_utmp_entries_max: Count = self.entries_stored_highest as Count;
94✔
1508
        let fixedstructreader_utmp_entries_hit: Count = self.entries_hits as Count;
94✔
1509
        let fixedstructreader_utmp_entries_miss: Count = self.entries_miss as Count;
94✔
1510
        let fixedstructreader_drop_entry_ok: Count = self.drop_entry_ok;
94✔
1511
        let fixedstructreader_drop_entry_errors: Count = self.drop_entry_errors;
94✔
1512
        let fixedstructreader_datetime_first = self.dt_first;
94✔
1513
        let fixedstructreader_datetime_last = self.dt_last;
94✔
1514
        let fixedstructreader_map_tvpair_fo_max_len: usize = self.map_tvpair_fo_max_len;
94✔
1515

1516
        SummaryFixedStructReader {
94✔
1517
            fixedstructreader_fixedstructtype_opt,
94✔
1518
            fixedstructreader_filetypefixedstruct_opt,
94✔
1519
            fixedstructreader_fixedstruct_size: self.fixedstruct_size(),
94✔
1520
            fixedstructreader_high_score,
94✔
1521
            fixedstructreader_utmp_entries,
94✔
1522
            fixedstructreader_first_entry_fileoffset,
94✔
1523
            fixedstructreader_entries_out_of_order,
94✔
1524
            fixedstructreader_utmp_entries_max,
94✔
1525
            fixedstructreader_utmp_entries_hit,
94✔
1526
            fixedstructreader_utmp_entries_miss,
94✔
1527
            fixedstructreader_drop_entry_ok,
94✔
1528
            fixedstructreader_drop_entry_errors,
94✔
1529
            fixedstructreader_datetime_first,
94✔
1530
            fixedstructreader_datetime_last,
94✔
1531
            fixedstructreader_map_tvpair_fo_max_len,
94✔
1532
        }
94✔
1533
    }
94✔
1534

1535
    /// Return an up-to-date [`Summary`] instance for this `FixedStructReader`.
1536
    ///
1537
    /// [`Summary`]: crate::readers::summary::Summary
1538
    pub fn summary_complete(&self) -> Summary {
93✔
1539
        let path = self.path().clone();
93✔
1540
        let path_ntf = None;
93✔
1541
        let filetype = self.filetype();
93✔
1542
        let logmessagetype = filetype.to_logmessagetype();
93✔
1543
        let summaryblockreader = self.blockreader.summary();
93✔
1544
        let summaryfixedstructreader = self.summary();
93✔
1545
        let error: Option<String> = self.error.clone();
93✔
1546

1547
        Summary::new(
93✔
1548
            path,
93✔
1549
            path_ntf,
93✔
1550
            filetype,
93✔
1551
            logmessagetype,
93✔
1552
            Some(summaryblockreader),
93✔
1553
            None,
93✔
1554
            None,
93✔
1555
            None,
93✔
1556
            Some(summaryfixedstructreader),
93✔
1557
            None,
93✔
1558
            None,
93✔
1559
            None,
93✔
1560
            error,
93✔
1561
        )
1562
    }
93✔
1563
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc