forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PackObj.h
66 lines (44 loc) · 1.7 KB
/
PackObj.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
#pragma once
class PackObj
{
public:
PackObj();
virtual ~PackObj();
// Use both names? One will call the other?
virtual ULONG GetPackSize();
virtual ULONG pack_size();
// The main packing calls.
virtual ULONG Pack(BYTE** ppData, ULONG iSize) { return 0; }
virtual BOOL UnPack(BYTE** ppData, ULONG iSize) { return TRUE; };
// Packing functions
static BOOL ALIGN_PTR(BYTE** ppData, ULONG* piSize);
template< typename ValType, typename OutputType >
static BOOL UNPACK_TYPE(OutputType* pBuffer, BYTE** ppData, ULONG* piSize)
{
if ((*piSize) < sizeof(ValType))
return FALSE;
*pBuffer = (OutputType)(*((ValType *)*ppData));
*ppData = (*ppData) + sizeof(ValType);
*piSize = (*piSize) - sizeof(ValType);
return TRUE;
}
template< typename ValType, typename InputType >
static BOOL PACK_TYPE(const InputType Buffer, BYTE** ppData, ULONG* piSize)
{
if ((*piSize) < sizeof(ValType))
return FALSE;
*((ValType *)(*ppData)) = Buffer;
*ppData = (*ppData) + sizeof(ValType);
*piSize = (*piSize) - sizeof(ValType);
return TRUE;
}
};
// UnPack Variables
#define UNPACK(type, output_var) PackObj::UNPACK_TYPE< type >(&output_var, ppData, &iSize)
#define UNPACK_POBJ(pobj) pobj->UnPack(ppData, iSize)
#define UNPACK_OBJ(obj) obj.UnPack(ppData, iSize)
#define PACK(type, input_var) PackObj::PACK_TYPE< type >(input_var, ppData, &iSize)
#define PACK_POBJ(pobj) pobj->Pack(ppData, iSize)
#define PACK_OBJ(obj) obj.Pack(ppData, iSize)
#define PACK_ALIGN() PackObj::ALIGN_PTR(ppData, &iSize)
#define FBitSet(flags, bit) ((((DWORD)flags) >> (bit)) & 1)