Scope: save/load traces memory (2)

pull/228/head
f4exb 2018-10-15 08:45:44 +02:00
rodzic 5d57f40e83
commit 64cf05f1c6
2 zmienionych plików z 95 dodań i 0 usunięć

Wyświetl plik

@ -90,6 +90,7 @@ public:
} }
typename std::vector<T>::iterator getCurrent() const { return m_current + m_size; } typename std::vector<T>::iterator getCurrent() const { return m_current + m_size; }
typename std::vector<T>::iterator begin() const { return m_data.begin(); }
unsigned int absoluteFill() const { return m_current - m_data.begin(); } unsigned int absoluteFill() const { return m_current - m_data.begin(); }
void reset() { m_current = m_data.begin(); } void reset() { m_current = m_data.begin(); }

Wyświetl plik

@ -20,6 +20,8 @@
#include <QDebug> #include <QDebug>
#include <QColor> #include <QColor>
#include <QByteArray>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include <math.h> #include <math.h>
@ -599,6 +601,44 @@ private:
} }
SampleVector::iterator current() { return m_traceBuffer.getCurrent(); } SampleVector::iterator current() { return m_traceBuffer.getCurrent(); }
QByteArray serialize() const
{
SimpleSerializer s(1);
QByteArray buffer = m_traceBuffer.serialize();
unsigned int endDelta = m_endPoint - m_traceBuffer.begin();
s.writeU32(1, endDelta);
s.writeBlob(2, buffer);
return s.final();
}
bool deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid()) {
return false;
}
if (d.getVersion() == 1)
{
unsigned int tmpUInt;
QByteArray buf;
d.readU32(1, &tmpUInt, 0);
d.readBlob(2, &buf);
m_traceBuffer.deserialize(buf);
m_endPoint = m_traceBuffer.begin() + tmpUInt;
return true;
}
else
{
return false;
}
}
}; };
struct TraceBackDiscreteMemory struct TraceBackDiscreteMemory
@ -672,6 +712,60 @@ private:
* Return current memory index * Return current memory index
*/ */
uint32_t currentIndex() const { return m_currentMemIndex; } uint32_t currentIndex() const { return m_currentMemIndex; }
/**
* Serializer
*/
QByteArray serialize() const
{
SimpleSerializer s(1);
s.writeU32(1, m_memSize);
s.writeU32(2, m_currentMemIndex);
s.writeU32(3, m_traceSize);
for (unsigned int i = 0; i < m_memSize; i++)
{
QByteArray buffer = m_traceBackBuffers[i].serialize();
s.writeBlob(100+i, buffer);
}
return s.final();
}
/**
* Deserializer
*/
bool deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid()) {
return false;
}
if (d.getVersion() == 1)
{
d.readU32(1, &m_memSize, 0);
d.readU32(2, &m_currentMemIndex, 0);
d.readU32(3, &m_traceSize, 0);
m_traceBackBuffers.resize(m_memSize);
resize(m_traceSize);
for (unsigned int i = 0; i < m_memSize; i++)
{
QByteArray buffer;
d.readBlob(100+i, &buffer);
m_traceBackBuffers[i].deserialize(buffer);
}
return true;
}
else
{
return false;
}
}
}; };
/** /**