Session test
This commit is contained in:
parent
7838e740a7
commit
9889d41805
|
@ -41,12 +41,12 @@ public:
|
|||
{
|
||||
const uint32_t lastIdx = currentChunk->getStartIndex() + currentChunk->numMeasurements();
|
||||
if( lastIdx <= startIdx) {
|
||||
encoder.sendArray(nullptr, 0);
|
||||
encoder.template sendArray<Measurement_T>(nullptr, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
Chunk_T::sendHeader(encoder, currentChunk->getStartTime(), startIdx);
|
||||
encoder.sendArrayHeader(lastIdx - startIdx);
|
||||
encoder.template sendArrayHeader<Measurement_T>(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<T> & encoder, uint32_t startIdx) {
|
||||
uint32_t serializeChunk(StreamingMsgPackEncoder<T> & 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<Measurement_T>(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<T>());
|
||||
|
||||
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<Measurement_T>(buffer, PART_SIZE);
|
||||
}
|
||||
}
|
||||
return startIdx + CHUNK_SIZE;
|
||||
|
|
|
@ -76,6 +76,7 @@ public:
|
|||
StreamingMsgPackEncoder<T> encoder(nullptr);
|
||||
encoder.setSizeCountMode(true);
|
||||
sendHeader(encoder, 0, 0);
|
||||
encoder.template sendArrayHeader<Measurement_T>(0);
|
||||
return encoder.getContentLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
const uint32_t SESSION_SIZE = 128;
|
||||
typedef Session<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
|
||||
|
||||
template<typename Measurement_T>
|
||||
std::vector<Measurement_T> 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<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> 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<uint8_t> data;
|
||||
VectorAdaptor adaptor( &data );
|
||||
StreamingMsgPackEncoder<VectorAdaptor> encoder(&adaptor);
|
||||
session.serialize(encoder, 0);
|
||||
uint32_t readStartTime=0;
|
||||
uint32_t readStartIndex=0;
|
||||
auto result = parseMessagePack<uint16_t>(&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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue