2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_SHARED_PACKER_H
|
|
|
|
#define ENGINE_SHARED_PACKER_H
|
|
|
|
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
class CPacker
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PACKER_BUFFER_SIZE=1024*2
|
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
unsigned char m_aBuffer[PACKER_BUFFER_SIZE];
|
|
|
|
unsigned char *m_pCurrent;
|
|
|
|
unsigned char *m_pEnd;
|
|
|
|
int m_Error;
|
|
|
|
public:
|
|
|
|
void Reset();
|
|
|
|
void AddInt(int i);
|
|
|
|
void AddString(const char *pStr, int Limit);
|
2010-05-29 07:25:38 +00:00
|
|
|
void AddRaw(const void *pData, int Size);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int Size() const { return (int)(m_pCurrent-m_aBuffer); }
|
|
|
|
const unsigned char *Data() const { return m_aBuffer; }
|
|
|
|
bool Error() const { return m_Error; }
|
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
class CUnpacker
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
const unsigned char *m_pStart;
|
|
|
|
const unsigned char *m_pCurrent;
|
|
|
|
const unsigned char *m_pEnd;
|
|
|
|
int m_Error;
|
|
|
|
public:
|
2010-08-12 13:22:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SANITIZE=1,
|
|
|
|
SANITIZE_CC=2,
|
|
|
|
SKIP_START_WHITESPACES=4
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Reset(const void *pData, int Size);
|
2009-10-27 14:38:53 +00:00
|
|
|
int GetInt();
|
2010-08-12 13:22:07 +00:00
|
|
|
const char *GetString(int SanitizeType = SANITIZE);
|
2009-10-27 14:38:53 +00:00
|
|
|
const unsigned char *GetRaw(int Size);
|
|
|
|
bool Error() const { return m_Error; }
|
|
|
|
};
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#endif
|