2020-06-21 11:10:45 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-17 23:26:17 +02:00
|
|
|
#include "StreamingMsgPackEncoder.h"
|
2019-08-22 21:33:36 +02:00
|
|
|
#include <cstdint>
|
2019-08-17 23:26:17 +02:00
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
template <typename Measurement_T, uint32_t SIZE>
|
2019-08-17 23:26:17 +02:00
|
|
|
class SessionChunk
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SessionChunk()
|
2020-06-21 11:10:45 +02:00
|
|
|
: nextFree_(0), sessionStartTime(0), startIndex(0)
|
2020-06-28 10:30:01 +02:00
|
|
|
{
|
|
|
|
}
|
2019-08-17 23:26:17 +02:00
|
|
|
|
|
|
|
void init(uint32_t epochStartTime, uint32_t startIdx)
|
|
|
|
{
|
2020-06-21 11:10:45 +02:00
|
|
|
nextFree_ = 0;
|
2019-08-17 23:26:17 +02:00
|
|
|
sessionStartTime = epochStartTime;
|
|
|
|
startIndex = startIdx;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
uint32_t getStartTime() const
|
|
|
|
{
|
2019-08-17 23:26:17 +02:00
|
|
|
return sessionStartTime;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
uint32_t getStartIndex() const
|
|
|
|
{
|
2019-08-17 23:26:17 +02:00
|
|
|
return startIndex;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
uint32_t numMeasurements() const
|
|
|
|
{
|
2020-06-21 11:10:45 +02:00
|
|
|
return nextFree_;
|
2019-08-17 23:26:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool addPoint(Measurement_T measurement)
|
|
|
|
{
|
2020-06-28 10:30:01 +02:00
|
|
|
if (nextFree_ >= SIZE)
|
2019-08-17 23:26:17 +02:00
|
|
|
return false;
|
2020-06-21 11:10:45 +02:00
|
|
|
values[nextFree_] = measurement;
|
|
|
|
nextFree_++;
|
2019-08-17 23:26:17 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
template <typename T>
|
|
|
|
void serialize(StreamingMsgPackEncoder<T> &encoder) const
|
2019-08-17 23:26:17 +02:00
|
|
|
{
|
|
|
|
sendHeader(encoder, sessionStartTime, startIndex);
|
2020-06-21 11:10:45 +02:00
|
|
|
encoder.sendArray(values, nextFree_);
|
2019-08-17 23:26:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t valueOffset()
|
|
|
|
{
|
2019-09-08 18:00:09 +02:00
|
|
|
StreamingMsgPackEncoder<DummyWriter> encoder(nullptr);
|
2019-08-17 23:26:17 +02:00
|
|
|
encoder.setSizeCountMode(true);
|
|
|
|
sendHeader(encoder, 0, 0);
|
2019-08-18 19:58:13 +02:00
|
|
|
encoder.template sendArrayHeader<Measurement_T>(0);
|
2019-08-17 23:26:17 +02:00
|
|
|
return encoder.getContentLength();
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
static uint32_t arrayHeaderOffset()
|
|
|
|
{
|
|
|
|
StreamingMsgPackEncoder<DummyWriter> encoder(nullptr);
|
|
|
|
encoder.setSizeCountMode(true);
|
|
|
|
sendHeader(encoder, 0, 0);
|
|
|
|
return encoder.getContentLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
Measurement_T *getDataPointer()
|
|
|
|
{
|
2019-08-17 23:26:17 +02:00
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
const Measurement_T *getDataPointer() const
|
|
|
|
{
|
2019-08-17 23:26:17 +02:00
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:30:01 +02:00
|
|
|
template <typename Encoder_T>
|
|
|
|
static void sendHeader(Encoder_T &encoder, uint32_t sessionStartTime, uint32_t startIndex)
|
2019-08-17 23:26:17 +02:00
|
|
|
{
|
|
|
|
encoder.sendMap16(3);
|
|
|
|
|
|
|
|
encoder.sendString255("sessionStartTime");
|
|
|
|
encoder.sendInt(sessionStartTime);
|
|
|
|
|
|
|
|
encoder.sendString255("startIndex");
|
|
|
|
encoder.sendInt(startIndex);
|
|
|
|
|
|
|
|
encoder.sendString255("values");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-06-21 11:10:45 +02:00
|
|
|
uint32_t nextFree_ = 0;
|
2019-08-17 23:26:17 +02:00
|
|
|
uint32_t sessionStartTime;
|
|
|
|
uint32_t startIndex;
|
|
|
|
Measurement_T values[SIZE];
|
|
|
|
};
|