diff --git a/lib/main/io_devices/pibinarylog.cpp b/lib/main/io_devices/pibinarylog.cpp index 2fd71564..bae32580 100644 --- a/lib/main/io_devices/pibinarylog.cpp +++ b/lib/main/io_devices/pibinarylog.cpp @@ -374,7 +374,7 @@ void PIBinaryLog::setHeader(const PIByteArray & header) { PIByteArray PIBinaryLog::getHeader() { - return user_header_readed; + return binfo.user_header; } @@ -436,7 +436,7 @@ bool PIBinaryLog::writeFileHeader() { bool PIBinaryLog::checkFileHeader() { - user_header_readed.clear(); + binfo.user_header.clear(); uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE]; for (uint i=0; i 0) { - user_header_readed = file.read(sz); + binfo.user_header = file.read(sz); } return true; } @@ -505,33 +505,37 @@ PIBinaryLog::BinLogRecord PIBinaryLog::readRecord() { void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector * index) { - BinLogInfo * bi = info; - bool ginfo = info != 0; - bool gindex = index != 0; - if (!ginfo && !gindex) return; - if (ginfo) { - bi->log_size = -1; - bi->records_count = 0; - bi->records.clear(); + if (!info && !index) return; + if (info) { + info->log_size = -1; + info->records_count = 0; + info->records.clear(); } - if (gindex) index->clear(); + if (index) index->clear(); if (f == 0) return; if (!f->canRead()) return; - if (ginfo) { - bi->path = f->path(); - bi->log_size = f->size(); + if (info) { + info->path = f->path(); + info->log_size = f->size(); } uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE]; for (uint i=0; iread(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) {if (ginfo) bi->records_count = -1; ok = false;} + if (f->read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) {if (info) info->records_count = -1; ok = false;} for (uint i=0; irecords_count = -2; ok = false;} + if (read_sig[i] != binlog_sig[i]) {if (info) info->records_count = -2; ok = false;} uchar read_version = 0; - if (f->read(&read_version, 1) < 0) {if (ginfo) bi->records_count = -3; ok = false;} - if (read_version == 0) {if (ginfo) bi->records_count = -4; ok = false;} - if (read_version < PIBINARYLOG_VERSION) {if (ginfo) bi->records_count = -5; ok = false;} - if (read_version > PIBINARYLOG_VERSION) {if (ginfo) bi->records_count = -6; ok = false;} + if (f->read(&read_version, 1) < 0) {if (info) info->records_count = -3; ok = false;} + if (read_version == 0) {if (info) info->records_count = -4; ok = false;} + if (read_version < PIBINARYLOG_VERSION_OLD) {if (info) info->records_count = -5; ok = false;} + if (read_version > PIBINARYLOG_VERSION) {if (info) info->records_count = -6; ok = false;} + if (read_version == PIBINARYLOG_VERSION) { + uint32_t sz = 0; + f->read(&sz, 4); + if (sz > 0 && info) { + info->user_header = f->read(sz); + } + } if (!ok) return; PIByteArray ba; BinLogRecord br; @@ -545,26 +549,26 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector< ba >> br.id >> br.size >> br.timestamp; } else break; - if (bi->log_size - f->pos() >= br.size) + if (info->log_size - f->pos() >= br.size) f->seek(f->pos() + br.size); else break; } if (br.id > 0) { - if (gindex) { + if (info) { BinLogIndex bl_ind; bl_ind.id = br.id; bl_ind.pos = f->pos() - br.size - hdr_size; bl_ind.timestamp = br.timestamp; index->append(bl_ind); } - if (ginfo) { - bi->records_count++; + if (info) { + info->records_count++; if (first) { - bi->start_time = br.timestamp; + info->start_time = br.timestamp; first = false; } - BinLogRecordInfo &bri(bi->records[br.id]); + BinLogRecordInfo &bri(info->records[br.id]); bri.count++; if (bri.id == 0) { bri.id = br.id; @@ -578,7 +582,7 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector< } } } - if (ginfo) bi->end_time = br.timestamp; + if (info) info->end_time = br.timestamp; } diff --git a/lib/main/io_devices/pibinarylog.h b/lib/main/io_devices/pibinarylog.h index 13ee83d5..9a835c4b 100644 --- a/lib/main/io_devices/pibinarylog.h +++ b/lib/main/io_devices/pibinarylog.h @@ -70,6 +70,7 @@ public: PISystemTime start_time; PISystemTime end_time; PIMap records; + PIByteArray user_header; }; //! \brief Struct contains position, ID and timestamp of record in file @@ -319,7 +320,7 @@ private: llong split_size, log_size; int write_count, split_count, default_id, current_index; bool is_started, is_thread_ok, is_indexed, rapid_start, is_pause; - PIByteArray user_header, user_header_readed; + PIByteArray user_header; }; //! \relatesalso PICout \relatesalso PIBinaryLog::BinLogInfo \brief Output operator to PICout