git-svn-id: svn://db.shs.com.ru/pip@167 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2015-12-15 12:50:12 +00:00
parent f8bde3792e
commit 2d687cec93
4 changed files with 67 additions and 13 deletions

View File

@@ -209,6 +209,10 @@ void PIBinaryLog::createNewFile(const PIString &path) {
int PIBinaryLog::writeBinLog(int id, const void *data, int size) {
if (size <= 0 || !canWrite()) return -1;
if (id == 0) {
piCoutObj << "Error: can`t write with id = 0!";
return -1;
}
switch (split_mode) {
case SplitSize:
if (logSize() > split_size) createNewFile();
@@ -243,7 +247,7 @@ int PIBinaryLog::writeBinLog_raw(int id, const PISystemTime &time, const void *d
}
PIByteArray PIBinaryLog::readBinLog(int id) {
PIByteArray PIBinaryLog::readBinLog(int id, PISystemTime * time) {
if (!canRead()) return PIByteArray();
BinLogRecord br = readRecord();
if (br.id == -1) {
@@ -258,15 +262,19 @@ PIByteArray PIBinaryLog::readBinLog(int id) {
fileEnd();
return PIByteArray();
}
if (br.id == id) return br.data;
if (br.id == id) {
if (time)
*time = br.timestamp;
return br.data;
}
piCoutObj << "Can't find record with id =" << id;
return PIByteArray();
}
int PIBinaryLog::readBinLog(int id, void *read_to, int max_size) {
int PIBinaryLog::readBinLog(int id, void *read_to, int max_size, PISystemTime * time) {
if (max_size <= 0 || read_to == 0) return -1;
PIByteArray ba = readBinLog(id);
PIByteArray ba = readBinLog(id, time);
if (ba.isEmpty()) return -1;
int sz = piMini(max_size, ba.size());
memcpy(read_to, ba.data(), sz);