forked from derandark/PhatAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryWriter.h
76 lines (63 loc) · 1.95 KB
/
BinaryWriter.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
class BinaryWriter
{
public:
BinaryWriter();
~BinaryWriter();
void ExpandBuffer(size_t len);
void AppendString(const char *szString);
void AppendData(const void *pData, size_t len);
void Align(void);
template <class DataT> void AppendData(DataT pData)
{
AppendData(&pData, sizeof(DataT));
}
__forceinline void WriteChar(char f00d) { AppendData(f00d); }
__forceinline void WriteShort(short f00d) { AppendData(f00d); }
__forceinline void WriteLong(long f00d) { AppendData(f00d); }
__forceinline void WriteFloat(float f00d) { AppendData(f00d); }
__forceinline void WriteDouble(double f00d) { AppendData(f00d); }
__forceinline void WriteBYTE(BYTE f00d) { AppendData(f00d); }
__forceinline void WriteWORD(WORD f00d) { AppendData(f00d); }
__forceinline void WriteDWORD(DWORD f00d) { AppendData(f00d); }
__forceinline void WritePackedDWORD(DWORD f00d) {
if (f00d < 0x8000)
{
WriteWORD((WORD)f00d);
}
else
{
WriteDWORD((f00d << 16) | ((f00d >> 16) | 0x8000));
}
}
__forceinline void WriteString(const char *f00d) { AppendString(f00d); }
__forceinline void WriteData(const void *data, size_t len) { AppendData(data, len); }
template<typename A, typename B> void WriteMap(std::map<A, B> &table)
{
WriteWORD((WORD) table.size());
WriteWORD(0x40);
for (std::map<A, B>::iterator keyValuePair = table.begin(); keyValuePair != table.end(); keyValuePair++)
{
AppendData((A)keyValuePair->first);
AppendData((B)keyValuePair->second);
}
}
template<typename A> void WriteMap(std::map<A, std::string> &table)
{
WriteWORD((WORD) table.size());
WriteWORD(0x40);
for (std::map<A, std::string>::iterator keyValuePair = table.begin(); keyValuePair != table.end(); keyValuePair++)
{
AppendData((A)keyValuePair->first);
AppendString(keyValuePair->second.c_str());
}
}
BYTE* GetData();
DWORD GetSize();
protected:
//BYTE m_pbData[0x800];
BYTE* m_pbData;
DWORD m_dwDataSize;
BYTE* m_pbDataPos;
DWORD m_dwSize;
};