binlog user header
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "pidir.h"
|
||||
#include "pipropertystorage.h"
|
||||
|
||||
#define PIBINARYLOG_VERSION_OLD 0x31
|
||||
|
||||
/*! \class PIBinaryLog
|
||||
* \brief Class for read and write binary data to logfile, and playback this data in realtime, or custom speed
|
||||
*
|
||||
@@ -356,6 +358,16 @@ int PIBinaryLog::readBinLog(int id, void *read_to, int max_size, PISystemTime *
|
||||
}
|
||||
|
||||
|
||||
void PIBinaryLog::setHeader(const PIByteArray & header) {
|
||||
user_header = header;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIBinaryLog::getHeader() {
|
||||
return user_header_readed;
|
||||
}
|
||||
|
||||
|
||||
int PIBinaryLog::readDevice(void *read_to, int max_size) {
|
||||
if (lastrecord.id == -1 || isEnd()) return 0;
|
||||
if(!is_thread_ok && lastrecord.id > 0) return lastrecord.data.size();
|
||||
@@ -405,12 +417,16 @@ bool PIBinaryLog::writeFileHeader() {
|
||||
if (file.write(&__S__PIBinaryLog::binlog_sig, PIBINARYLOG_SIGNATURE_SIZE) <= 0) return false;
|
||||
uchar version = PIBINARYLOG_VERSION;
|
||||
if (file.write(&version, 1) <= 0) return false;
|
||||
uint32_t sz = user_header.size();
|
||||
file.write(&sz, 4);
|
||||
file.write(user_header);
|
||||
file.flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PIBinaryLog::checkFileHeader() {
|
||||
user_header_readed.clear();
|
||||
uchar read_sig[PIBINARYLOG_SIGNATURE_SIZE];
|
||||
for (uint i=0; i<PIBINARYLOG_SIGNATURE_SIZE; i++) read_sig[i] = 0;
|
||||
if (file.read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) return false;
|
||||
@@ -423,8 +439,17 @@ bool PIBinaryLog::checkFileHeader() {
|
||||
}
|
||||
uchar read_version = 0;
|
||||
if (file.read(&read_version, 1) < 0) return false;
|
||||
if (read_version == PIBINARYLOG_VERSION_OLD) {
|
||||
log_size = file.size();
|
||||
return true;
|
||||
}
|
||||
if (read_version == PIBINARYLOG_VERSION) {
|
||||
log_size = file.size();
|
||||
uint32_t sz = 0;
|
||||
file.read(&sz, 4);
|
||||
if (sz > 0) {
|
||||
user_header_readed = file.read(sz);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (read_version == 0)
|
||||
|
||||
Reference in New Issue
Block a user