summaryrefslogtreecommitdiffstats
path: root/src/line_buffer.hh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/line_buffer.hh47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/line_buffer.hh b/src/line_buffer.hh
index e0d3218..1569198 100644
--- a/src/line_buffer.hh
+++ b/src/line_buffer.hh
@@ -46,13 +46,20 @@
#include "base/auto_mem.hh"
#include "base/file_range.hh"
#include "base/is_utf8.hh"
-#include "base/lnav_log.hh"
+#include "base/lnav.gzip.hh"
+#include "base/piper.file.hh"
#include "base/result.h"
+#include "log_level.hh"
+#include "mapbox/variant.hpp"
#include "safe/safe.h"
#include "shared_buffer.hh"
struct line_info {
file_range li_file_range;
+ struct timeval li_timestamp {
+ 0, 0
+ };
+ log_level_t li_level{LEVEL_UNKNOWN};
bool li_partial{false};
utf8_scan_result li_utf8_scan_result{};
};
@@ -77,19 +84,6 @@ public:
int e_err;
};
- struct header_data {
- timeval hd_mtime{};
- auto_buffer hd_extra{auto_buffer::alloc(0)};
- std::string hd_name;
- std::string hd_comment;
-
- bool empty() const
- {
- return this->hd_mtime.tv_sec == 0 && this->hd_extra.empty()
- && this->hd_name.empty() && this->hd_comment.empty();
- }
- };
-
#define GZ_WINSIZE 32768U /*> gzip's max supported dictionary is 15-bits */
#define GZ_RAW_MODE (-15) /*> Raw inflate data mode */
#define GZ_HEADER_MODE (15 + 32) /*> Automatic zstd or gzip decoding */
@@ -117,7 +111,7 @@ public:
void close();
void init_stream();
void continue_stream();
- void open(int fd, header_data& hd);
+ void open(int fd, lnav::gzip::header& hd);
int stream_data(void* buf, size_t size);
void seek(off_t offset);
@@ -175,6 +169,10 @@ public:
bool is_compressed() const { return this->lb_compressed; }
+ bool is_header_utf8() const { return this->lb_is_utf8; }
+
+ bool has_line_metadata() const { return this->lb_line_metadata; }
+
file_off_t get_read_offset(file_off_t off) const
{
if (this->is_compressed()) {
@@ -255,10 +253,22 @@ public:
size_t get_buffer_size() const { return this->lb_buffer.size(); }
- const header_data& get_header_data() const { return this->lb_header; }
+ using file_header_t
+ = mapbox::util::variant<lnav::gzip::header, lnav::piper::header>;
+
+ const file_header_t& get_header_data() const { return this->lb_header; }
void enable_cache();
+ file_ssize_t get_piper_header_size() const
+ {
+ return this->lb_piper_header_size;
+ }
+
+ bool is_piper() const { return this->lb_piper_header_size > 0; }
+
+ size_t line_count_guess() const { return this->lb_line_starts.size(); }
+
static void cleanup_cache();
private:
@@ -331,6 +341,8 @@ private:
auto_fd lb_fd; /*< The file to read data from. */
safe_gz_indexed lb_gz_file; /*< File reader for gzipped files. */
bool lb_bz_file{false}; /*< Flag set for bzip2 compressed files. */
+ bool lb_line_metadata{false};
+ file_ssize_t lb_piper_header_size{0};
auto_buffer lb_buffer{auto_buffer::alloc(DEFAULT_LINE_BUFFER_SIZE)};
nonstd::optional<auto_buffer> lb_alt_buffer;
@@ -355,6 +367,7 @@ private:
time_t lb_file_time{0};
bool lb_seekable{false}; /*< Flag set for seekable file descriptors. */
bool lb_compressed{false};
+ bool lb_is_utf8{true};
file_off_t lb_last_line_offset{-1}; /*< */
std::vector<uint32_t> lb_line_starts;
@@ -364,7 +377,7 @@ private:
nonstd::optional<auto_fd> lb_cached_fd;
- header_data lb_header;
+ file_header_t lb_header{mapbox::util::no_init{}};
};
#endif