binlog user header
This commit is contained in:
@@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
project(pip)
|
||||
set(_PIP_MAJOR 2)
|
||||
set(_PIP_MINOR 0)
|
||||
set(_PIP_MINOR 1)
|
||||
set(_PIP_REVISION 0)
|
||||
set(_PIP_SUFFIX _prealpha)
|
||||
set(_PIP_SUFFIX _alpha)
|
||||
set(_PIP_COMPANY SHS)
|
||||
set(_PIP_DOMAIN org.SHS)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "pifile.h"
|
||||
|
||||
#define PIBINARYLOG_VERSION 0x31
|
||||
#define PIBINARYLOG_VERSION 0x32
|
||||
namespace __S__PIBinaryLog {
|
||||
static const uchar binlog_sig[] = {'B','I','N','L','O','G'};
|
||||
}
|
||||
@@ -207,7 +207,12 @@ public:
|
||||
//! Returns timestamp of last readed record
|
||||
PISystemTime lastReadedTimestamp() const {return lastrecord.timestamp;}
|
||||
|
||||
|
||||
//!Set custom file header, you can get it back when read this binlog
|
||||
void setHeader(const PIByteArray & header);
|
||||
|
||||
//!Get custom file header
|
||||
PIByteArray getHeader();
|
||||
|
||||
#ifdef DOXYGEN
|
||||
//! Read one message from binlog file, with ID contains in "filterID" or any ID, if "filterID" is empty
|
||||
int read(void *read_to, int max_size);
|
||||
@@ -321,6 +326,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;
|
||||
};
|
||||
|
||||
//! \relatesalso PICout \relatesalso PIBinaryLog::BinLogInfo \brief Output operator to PICout
|
||||
|
||||
Reference in New Issue
Block a user