about summary refs log tree commit diff
path: root/src/engine/shared/packer.h
blob: 7a98501aced77544fd0916d23616f317dde8fc3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef ENGINE_SHARED_PACKER_H
#define ENGINE_SHARED_PACKER_H



class CPacker
{
	enum
	{
		PACKER_BUFFER_SIZE=1024*2
	};

	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);
	void AddRaw(const void *pData, int Size);
	
	int Size() const { return (int)(m_pCurrent-m_aBuffer); }
	const unsigned char *Data() const { return m_aBuffer; }
	bool Error() const { return m_Error; }
};

class CUnpacker
{
	const unsigned char *m_pStart;
	const unsigned char *m_pCurrent;
	const unsigned char *m_pEnd;
	int m_Error;
public:
	void Reset(const void *pData, int Size);
	int GetInt();
	const char *GetString();
	const unsigned char *GetRaw(int Size);
	bool Error() const { return m_Error; }
};

#endif