EthPacketData::serialize(const string &base, CheckpointOut &cp) const
{
paramOut(cp, base + ".simLength", simLength);
+ paramOut(cp, base + ".bufLength", bufLength);
paramOut(cp, base + ".length", length);
arrayParamOut(cp, base + ".data", data, length);
}
EthPacketData::unserialize(const string &base, CheckpointIn &cp)
{
paramIn(cp, base + ".length", length);
- if (length) {
- assert(data == nullptr);
- data = new uint8_t[length];
- arrayParamIn(cp, base + ".data", data, length);
+ unsigned chkpt_buf_length;
+ if (optParamIn(cp, base + ".bufLength", chkpt_buf_length)) {
+ // If bufLength is in the checkpoint, make sure that the current buffer
+ // is unallocated or that the checkpoint requested size is smaller than
+ // the current buffer.
+ assert(!data || chkpt_buf_length <= bufLength);
+ bufLength = chkpt_buf_length;
+ } else {
+ // If bufLength is not in the checkpoint, try to use the existing
+ // buffer or use length to size the buffer
+ if (!data)
+ bufLength = length;
}
+ assert(length <= bufLength);
+ if (!data)
+ data = new uint8_t[bufLength];
+ arrayParamIn(cp, base + ".data", data, length);
if (!optParamIn(cp, base + ".simLength", simLength))
simLength = length;
}
*/
uint8_t *data;
+ /**
+ * Total size of the allocated data buffer.
+ */
+ unsigned bufLength;
+
/**
* Amount of space occupied by the payload in the data buffer
*/
unsigned simLength;
EthPacketData()
- : data(nullptr), length(0), simLength(0)
+ : data(nullptr), bufLength(0), length(0), simLength(0)
{ }
explicit EthPacketData(unsigned size)
- : data(new uint8_t[size]), length(0), simLength(0)
+ : data(new uint8_t[size]), bufLength(size), length(0), simLength(0)
{ }
~EthPacketData() { if (data) delete [] data; }
UNSERIALIZE_SCALAR(txPacketExists);
txPacket = 0;
if (txPacketExists) {
- txPacket = make_shared<EthPacketData>();
+ txPacket = make_shared<EthPacketData>(16384);
txPacket->unserialize("txPacket", cp);
UNSERIALIZE_SCALAR(txPacketOffset);
UNSERIALIZE_SCALAR(txPacketBytes);