From 294831df17e73c3a63a52f960c17a56ba3741191 Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 12 Aug 2020 20:01:24 +0300 Subject: [PATCH] binlog user header --- CMakeLists.txt | 4 ++-- lib/main/io_devices/pibinarylog.cpp | 25 +++++++++++++++++++++++++ lib/main/io_devices/pibinarylog.h | 10 ++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d00630a9..53269b61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/lib/main/io_devices/pibinarylog.cpp b/lib/main/io_devices/pibinarylog.cpp index c1e46d4d..ebd44728 100644 --- a/lib/main/io_devices/pibinarylog.cpp +++ b/lib/main/io_devices/pibinarylog.cpp @@ -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 0) { + user_header_readed = file.read(sz); + } return true; } if (read_version == 0) diff --git a/lib/main/io_devices/pibinarylog.h b/lib/main/io_devices/pibinarylog.h index 6703dcf0..f9b4bab7 100644 --- a/lib/main/io_devices/pibinarylog.h +++ b/lib/main/io_devices/pibinarylog.h @@ -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