2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
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
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2020-09-03 16:50:23 +00:00
|
|
|
public:
|
2009-10-27 14:38:53 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
PACKER_BUFFER_SIZE = 1024 * 2
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2020-09-03 16:50:23 +00:00
|
|
|
private:
|
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;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
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);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
int Size() const { return (int)(m_pCurrent - m_aBuffer); }
|
2009-10-27 14:38:53 +00:00
|
|
|
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;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
2010-08-12 13:22:07 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
SANITIZE = 1,
|
|
|
|
SANITIZE_CC = 2,
|
|
|
|
SKIP_START_WHITESPACES = 4
|
2010-08-12 13:22:07 +00:00
|
|
|
};
|
|
|
|
|
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();
|
2020-04-16 08:46:43 +00:00
|
|
|
int GetIntOrDefault(int Default);
|
2022-06-22 21:46:25 +00:00
|
|
|
int GetUncompressedInt();
|
|
|
|
int GetUncompressedIntOrDefault(int Default);
|
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; }
|
2017-09-13 20:35:09 +00:00
|
|
|
|
|
|
|
int CompleteSize() const { return m_pEnd - m_pStart; }
|
|
|
|
const unsigned char *CompleteData() const { return m_pStart; }
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#endif
|