forked from InfiniteRasa/Game-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacking.h
85 lines (68 loc) · 2.38 KB
/
Packing.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
77
78
79
80
81
82
83
84
85
/*
Helper for creating and parsing PyMarshal Strings without having Python.
Also this should be much faster than the original Python methods.
*/
typedef struct
{
sint8 type; //'t' tuple, 'd' dict
// general
sint32 startOffset;
sint32 subelements;
// dict info
// tuple info
//sint32 tupleSize;
}containerStackEntry_t;
typedef struct
{
uint8 buffer[2048];
sint32 bufferSize;
sint32 idx;
containerStackEntry_t containerStack[16];
sint32 stackIdx;
}pyMarshalString_t;
// new marshal packing lib
void pym_init(pyMarshalString_t *pms);
void pym_tuple_begin(pyMarshalString_t *pms);
void pym_tuple_end(pyMarshalString_t *pms);
void pym_list_begin(pyMarshalString_t *pms);
void pym_list_end(pyMarshalString_t *pms);
void pym_dict_begin(pyMarshalString_t *pms);
void pym_dict_end(pyMarshalString_t *pms);
void pym_dict_addKey(pyMarshalString_t *pms, sint8 *s);
void pym_addInt(pyMarshalString_t *pms, sint32 value);
void pym_addLong(pyMarshalString_t *pms, long long value);
void pym_addString(pyMarshalString_t *pms, sint8 *s);
void pym_addUnicode(pyMarshalString_t *pms, sint8 *s);
void pym_addNoneStruct(pyMarshalString_t *pms);
void pym_addBool(pyMarshalString_t *pms, bool b);
void pym_addFloat(pyMarshalString_t *pms, float value);
uint8 *pym_getData(pyMarshalString_t *pms);
uint32 pym_getLen(pyMarshalString_t *pms);
// new marshal unpacking lib
typedef struct
{
sint8 type; // 'd' - dict, 't' - tuple
uint32 size;
uint32 subelementsLeft;
}pyUnmarshalContainer_t;
typedef struct
{
uint8 *buffer;
sint32 idx;
sint32 len;
bool unpackErrorEncountered;
pyUnmarshalContainer_t containerStack[16];
sint32 stackIndex;
}pyUnmarshalString_t;
void pym_init(pyUnmarshalString_t *pms, uint8 *rawData, sint32 len);
bool pym_unpackTuple_begin(pyUnmarshalString_t *pms);
sint32 pym_unpackList_begin(pyUnmarshalString_t *pms);
bool pym_unpackDict_begin(pyUnmarshalString_t *pms);
sint32 pym_getContainerSize(pyUnmarshalString_t *pms);
sint32 pym_unpackInt(pyUnmarshalString_t *pms);
long long pym_unpackLongLong(pyUnmarshalString_t *pms);
sint32 pym_unpackUnicode(pyUnmarshalString_t *pms, sint8 *dst, sint32 limit);
float pym_unpackFloat(pyUnmarshalString_t *pms);
bool pym_unpackBool(pyUnmarshalString_t *pms);
bool pym_unpackNoneStruct(pyUnmarshalString_t *pms);
bool pym_unpack_isNoneStruct(pyUnmarshalString_t *pms);