ddnet/src/engine/shared/packer.h

50 lines
938 B
C
Raw Normal View History

2010-05-29 07:25:38 +00:00
#ifndef ENGINE_SHARED_PACKER_H
#define ENGINE_SHARED_PACKER_H
2009-10-27 14:38:53 +00:00
class CPacker
{
2009-10-27 14:38:53 +00:00
enum
{
PACKER_BUFFER_SIZE=1024*2
};
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);
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; }
};
2009-10-27 14:38:53 +00:00
class CUnpacker
{
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:
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();
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