#include "../shared/SimpleLogFile.h" #include "../shared/ThreadMonitor.h" #include "SerializeValuesByName.h" #include "AlertsOutput.h" void AlertsOutput::reportError(std::string const &type) { DeserializeRecords::reportError(type); } void AlertsOutput::clear() { startFromHere = -1; values.clear(); } bool AlertsOutput::loadFromString(std::string const &source) { clear(); const std::vector< Record::Ref > records = DeserializeRecords::getRecords(source); if (records.empty()) { reportError("loadFromString unable to parse records"); return false; } Record const &header = *records[0]; DeserializeRecords deserializer(header); FieldId fieldId = 0xffff; ValueBox value = header.lookUpValue(fieldId); bool success; int64_t intValue; value.getInt(success, intValue); if (!success) { reportError("loadFromString() error reading alert id"); return false; } startFromHere = intValue; int totalCount = 0; struct Window { std::string name; int64_t count; }; std::vector< Window > windows; while (true) { Window window; fieldId--; header.lookUpValue(fieldId).getInt(success, window.count); if (!success) break; totalCount += window.count; fieldId--; header.lookUpValue(fieldId).getString(success, window.name); if (!success) { reportError("loadFromString() error reading window name"); return false; } windows.push_back(window); } if (totalCount + 1 != (int)records.size()) { reportError("loadFromString() invalid number of records"); return false; } auto recordIt = records.begin(); recordIt++; for (auto windowIt = windows.begin(); windowIt != windows.end(); windowIt++) { auto &rows = values[windowIt->name]; for (int count = windowIt->count; count > 0; count--) { Record const &record = **recordIt; auto &row = nextItem(rows); if (!deserializer.go(row, record)) { clear(); return false; } recordIt++; } } assert(recordIt == records.end()); return true; } std::string AlertsOutput::saveToString() const { std::string result; RecordBuilder headerRecord; FieldId counterId = (FieldId)-1; headerRecord.append(counterId, startFromHere); SerializeRecords serializer; for (auto windowIt = values.begin(); windowIt != values.end(); windowIt++) { std::vector< Parse::ValuesByName > const &rows = windowIt->second; counterId--; headerRecord.append(counterId, (int)rows.size()); counterId--; headerRecord.append(counterId, windowIt->first); // Window Id for (auto rowIt = rows.begin(); rowIt != rows.end(); rowIt++) serializer.loadNames(headerRecord, *rowIt); } SerializeRecords::addRecord(result, headerRecord); for (auto windowIt = values.begin(); windowIt != values.end(); windowIt++) { std::vector< Parse::ValuesByName > const &rows = windowIt->second; for (auto rowIt = rows.begin(); rowIt != rows.end(); rowIt++) { RecordBuilder row; serializer.go(row, *rowIt); serializer.addRecord(result, row); } } return result; } std::string AlertsOutput::debugDump() const { TclList result; result<first; // window id std::vector< Parse::ValuesByName > const &rows = windowIt->second; ::debugDump(window, rows); result<first != *it2->first) return false; if (*it1->second != *it2->second) return false; } assert(it2 == other.values.end()); return true; */ return debugDump() == other.debugDump(); } void AlertsOutput::testOne() const { AlertsOutput other; const std::string asString = saveToString(); bool success = other.loadFromString(asString); bool equal = *this == other; TclList msg; msg<