Added Array versions of ReadRawData and ReadUserCmd

This commit is contained in:
Jordan Cristiano 2015-06-14 17:04:05 -04:00
parent 284a99fff7
commit 44c36ab0f2
2 changed files with 27 additions and 0 deletions

View File

@ -33,6 +33,24 @@ int32_t DemoFileReader::ReadRawData(uint8_t* buffer, int32_t maxLength)
return size; return size;
} }
Array<uint8_t> DemoFileReader::ReadRawData(int32_t maxLength)
{
FILE* fp = m_demoFp;
int32_t size;
fread(&size, sizeof(int32_t), 1, fp);
Array<uint8_t> data;
if (maxLength < size)
{
return std::move(data);
}
data.reset(size);
fread(data.begin(), 1, size, fp);
return std::move(data);
}
void DemoFileReader::ReadSequenceInfo(int32_t& seqNum1, int32_t& seqNum2) void DemoFileReader::ReadSequenceInfo(int32_t& seqNum1, int32_t& seqNum2)
{ {
FILE* fp = m_demoFp; FILE* fp = m_demoFp;
@ -66,6 +84,12 @@ int32_t DemoFileReader::ReadUserCmd(int32_t& cmdNum, uint8_t* buffer, int32_t ma
return ReadRawData(buffer, maxLength); return ReadRawData(buffer, maxLength);
} }
Array<uint8_t> DemoFileReader::ReadUserCmd(int32_t& cmdNum, int32_t maxLength)
{
fread(&cmdNum, sizeof(int32_t), 1, m_demoFp);
return ReadRawData(maxLength);
}
// DemoFileWriter // DemoFileWriter
DemoFileWriter::DemoFileWriter(FILE* fp) : DemoFileWriter::DemoFileWriter(FILE* fp) :

View File

@ -3,6 +3,7 @@
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include "base/array.h"
struct demoheader_t; struct demoheader_t;
struct democmdinfo_t; struct democmdinfo_t;
@ -14,10 +15,12 @@ public:
void ReadDemoHeader(demoheader_t& header); void ReadDemoHeader(demoheader_t& header);
int32_t ReadRawData(uint8_t* buffer, int32_t maxLength); int32_t ReadRawData(uint8_t* buffer, int32_t maxLength);
Array<uint8_t> ReadRawData(int32_t maxLength);
void ReadSequenceInfo(int32_t& seqNum1, int32_t& seqNum2); void ReadSequenceInfo(int32_t& seqNum1, int32_t& seqNum2);
void ReadCmdInfo(democmdinfo_t& info); void ReadCmdInfo(democmdinfo_t& info);
void ReadCmdHeader(unsigned char& cmd, int32_t& tick); void ReadCmdHeader(unsigned char& cmd, int32_t& tick);
int32_t ReadUserCmd(int32_t& cmdNum, uint8_t* buffer, int32_t maxLength); int32_t ReadUserCmd(int32_t& cmdNum, uint8_t* buffer, int32_t maxLength);
Array<uint8_t> ReadUserCmd(int32_t& cmdNum, int32_t maxLength);
private: private:
FILE* m_demoFp; FILE* m_demoFp;