DDraceNetwork Docs
packer.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_SHARED_PACKER_H
4#define ENGINE_SHARED_PACKER_H
5
6class CPacker
7{
8public:
9 enum
10 {
11 PACKER_BUFFER_SIZE = 1024 * 64
12 };
13
14private:
16 unsigned char *m_pCurrent;
17 unsigned char *m_pEnd;
18 bool m_Error;
19
20public:
21 void Reset();
22 void AddInt(int i);
23 void AddString(const char *pStr, int Limit = PACKER_BUFFER_SIZE);
24 void AddRaw(const void *pData, int Size);
25
26 int Size() const { return (int)(m_pCurrent - m_aBuffer); }
27 const unsigned char *Data() const { return m_aBuffer; }
28 bool Error() const { return m_Error; }
29};
30
32{
33 const unsigned char *m_pStart;
34 const unsigned char *m_pCurrent;
35 const unsigned char *m_pEnd;
36 bool m_Error;
37
38public:
39 enum
40 {
44 };
45
46 void Reset(const void *pData, int Size);
47 int GetInt();
48 int GetIntOrDefault(int Default);
50 int GetUncompressedIntOrDefault(int Default);
51 const char *GetString(int SanitizeType = SANITIZE);
52 const unsigned char *GetRaw(int Size);
53 bool Error() const { return m_Error; }
54
55 int CompleteSize() const { return m_pEnd - m_pStart; }
56 const unsigned char *CompleteData() const { return m_pStart; }
57};
58
59#endif
Definition: packer.h:7
const unsigned char * Data() const
Definition: packer.h:27
@ PACKER_BUFFER_SIZE
Definition: packer.h:11
unsigned char * m_pEnd
Definition: packer.h:17
void AddInt(int i)
Definition: packer.cpp:15
unsigned char m_aBuffer[PACKER_BUFFER_SIZE]
Definition: packer.h:15
void AddString(const char *pStr, int Limit=PACKER_BUFFER_SIZE)
Definition: packer.cpp:29
bool Error() const
Definition: packer.h:28
void Reset()
Definition: packer.cpp:8
int Size() const
Definition: packer.h:26
unsigned char * m_pCurrent
Definition: packer.h:16
void AddRaw(const void *pData, int Size)
Definition: packer.cpp:64
bool m_Error
Definition: packer.h:18
Definition: packer.h:32
int GetInt()
Definition: packer.cpp:87
bool m_Error
Definition: packer.h:36
const unsigned char * m_pEnd
Definition: packer.h:35
const unsigned char * GetRaw(int Size)
Definition: packer.cpp:189
int GetUncompressedInt()
Definition: packer.cpp:122
void Reset(const void *pData, int Size)
Definition: packer.cpp:79
@ SANITIZE
Definition: packer.h:41
@ SANITIZE_CC
Definition: packer.h:42
@ SKIP_START_WHITESPACES
Definition: packer.h:43
const unsigned char * m_pCurrent
Definition: packer.h:34
int GetUncompressedIntOrDefault(int Default)
Definition: packer.cpp:139
int CompleteSize() const
Definition: packer.h:55
const char * GetString(int SanitizeType=SANITIZE)
Definition: packer.cpp:152
const unsigned char * CompleteData() const
Definition: packer.h:56
int GetIntOrDefault(int Default)
Definition: packer.cpp:109
bool Error() const
Definition: packer.h:53
const unsigned char * m_pStart
Definition: packer.h:33