diff --git a/vrs/RecordFileReader.cpp b/vrs/RecordFileReader.cpp index be607cd2..31f75b09 100644 --- a/vrs/RecordFileReader.cpp +++ b/vrs/RecordFileReader.cpp @@ -43,6 +43,30 @@ using namespace std; +namespace { + +using namespace vrs; + +bool before(Record::Type lhs, Record::Type rhs) { + if (lhs == Record::Type::CONFIGURATION && rhs == Record::Type::STATE) { + return true; + } else if (lhs == Record::Type::STATE && rhs == Record::Type::CONFIGURATION) { + return false; + } + return static_cast(lhs) < static_cast(rhs); +} + +bool fullRecordCompare(const IndexRecord::RecordInfo& lhs, const IndexRecord::RecordInfo& rhs) { + return lhs.timestamp < rhs.timestamp || + (lhs.timestamp <= rhs.timestamp && + (lhs.streamId < rhs.streamId || + (lhs.streamId == rhs.streamId && + (before(lhs.recordType, rhs.recordType) || + (lhs.recordType == rhs.recordType && lhs.fileOffset < rhs.fileOffset))))); +} + +} // namespace + namespace vrs { StreamPlayer::~StreamPlayer() = default; @@ -311,6 +335,9 @@ int RecordFileReader::doOpenFile( streamRecordCounts_[record.streamId][record.recordType]++; } } + if (error == 0 && fileSpec.getExtraAsBool("sort_records", false)) { + sort(recordIndex_.begin(), recordIndex_.end(), fullRecordCompare); + } return error; }