diff --git a/session/Session.h b/session/Session.h index 58c4c9a..e52e036 100644 --- a/session/Session.h +++ b/session/Session.h @@ -41,12 +41,12 @@ public: { const uint32_t lastIdx = currentChunk->getStartIndex() + currentChunk->numMeasurements(); if( lastIdx <= startIdx) { - encoder.sendArray(nullptr, 0); + encoder.template sendArray(nullptr, 0); return; } Chunk_T::sendHeader(encoder, currentChunk->getStartTime(), startIdx); - encoder.sendArrayHeader(lastIdx - startIdx); + encoder.template sendArrayHeader(lastIdx - startIdx); while(startIdx < lastIdx) startIdx = serializeChunk(encoder, startIdx); assert(startIdx == lastIdx, "Not all data was sent"); @@ -79,7 +79,7 @@ private: }; template< typename T> - uint32_t serializeChunk(StreamingMsgPackEncoder & encoder, uint32_t startIdx) { + uint32_t serializeChunk(StreamingMsgPackEncoder & encoder, uint32_t startIdx) const { assert( startIdx < currentChunk->getStartIndex() + currentChunk->numMeasurements(), "serializeChunk: invalid startIdx" ); @@ -92,12 +92,12 @@ private: return otherChunk->getStartIndex() + otherChunk->numMeasurements(); } else { if( encoder.getSizeCountMode() ) { - encoder.sendArrayPartialContents(nullptr, CHUNK_SIZE); + encoder.template sendArrayPartialContents(nullptr, CHUNK_SIZE); } else { const uint32_t chunkNr = startIdx / CHUNK_SIZE; - const auto chunkFileName = (chunkNr, currentChunk->getStartTime()); - Reader reader(chunkFileName); - reader.seek(Chunk_T::valueOffset()); + const auto chunkFileNameStr = chunkFileName(chunkNr, currentChunk->getStartTime()); + Reader reader(chunkFileNameStr); + reader.seek(Chunk_T::template valueOffset()); const uint32_t PART_SIZE = 32; static_assert( PART_SIZE < CHUNK_SIZE && CHUNK_SIZE % PART_SIZE == 0); @@ -106,7 +106,7 @@ private: for(uint32_t i = 0; i < CHUNK_SIZE; i += PART_SIZE) { reader.readBytes((char*) buffer, sizeof(Measurement_T) * PART_SIZE); - encoder.sendArrayPartialContents(buffer, PART_SIZE); + encoder.template sendArrayPartialContents(buffer, PART_SIZE); } } return startIdx + CHUNK_SIZE; diff --git a/session/SessionChunk.h b/session/SessionChunk.h index 3d3f780..9881405 100644 --- a/session/SessionChunk.h +++ b/session/SessionChunk.h @@ -76,6 +76,7 @@ public: StreamingMsgPackEncoder encoder(nullptr); encoder.setSizeCountMode(true); sendHeader(encoder, 0, 0); + encoder.template sendArrayHeader(0); return encoder.getContentLength(); } diff --git a/sessiontest.cpp b/sessiontest.cpp index 4e6c636..8777f12 100644 --- a/sessiontest.cpp +++ b/sessiontest.cpp @@ -5,9 +5,6 @@ #include -const uint32_t SESSION_SIZE = 128; -typedef Session MockSession; - template std::vector parseMessagePack(const uint8_t * data, uint32_t &startTime, uint32_t &startIndex) { @@ -119,33 +116,39 @@ void testSessionChunkSerialization() } } +void testSession() { + const uint32_t SESSION_SIZE = 128; + typedef Session MockSession; + + const uint32_t startTime = 194842; + const uint_t fillSize = SESSION_SIZE * 4 + 7; + + MockSession session; + session.init(startTime); + for (uint16_t i = 0; i < fillSize; ++i) { + session.addPoint(i); + } + + std::vector data; + VectorAdaptor adaptor( &data ); + StreamingMsgPackEncoder encoder(&adaptor); + session.serialize(encoder, 0); + uint32_t readStartTime=0; + uint32_t readStartIndex=0; + auto result = parseMessagePack(&data[0], readStartTime, readStartIndex); + assert(readStartIndex == 0 && startTime == readStartTime, ""); + assert(result.size() == fillSize, "Wrong result array size"); + for( uint16_t i=0; i < fillSize; ++i) { + assert(result[i] == i, "Wrong array contents"); + } +} int main(int argc, char**argv) { testSessionChunkAdd(); testSessionChunkGetterSetter(); testSessionChunkSerialization(); - - //MockSession session; - - /* - std::string line; - while (std::getline(std::cin, line)) - { - std::stringstream lineStream(line); - std::string command; - lineStream >> command; - if( command == "add_points") { - uint16_t number; - lineStream >> number; - for( uint16_t i=0; i < number; ++i) { - session.addPoint(i); - } - } else if( command == "print_status") { - - } - } - */ + testSession(); return 0; }