-
Notifications
You must be signed in to change notification settings - Fork 0
/
StructureToFromBuffer.h
41 lines (33 loc) · 1.28 KB
/
StructureToFromBuffer.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
#include <stddef.h> // for offsetf()
/*---------------------------------------------------------------------------*/
// Constants
/*---------------------------------------------------------------------------*/
#define ENTRY(s, v) { sizeof(((s*)0)->v), offsetof(s, v) }
#define ENTRYEND {0, 0}
// Error codes
enum
{
NO_PAYLOAD_STRUCTURE = -1,
NO_INPUT_BUFFER = -2,
NO_ROOM_IN_INPUT_BUFFER = -3,
NO_OUTPUT_BUFFER = -4,
NO_ROOM_IN_OUTPUT_BUFFER = -5
};
/*---------------------------------------------------------------------------*/
// Typedefs
/*---------------------------------------------------------------------------*/
typedef struct
{
size_t size; // size of structure element
size_t offset; // offset from start of structure to that element
} ElementOffsetStruct;
/*---------------------------------------------------------------------------*/
// Prototypes
/*---------------------------------------------------------------------------*/
int StructureToBuffer (void *bufferPtr, unsigned int bufferSize,
void *structurePtr,
ElementOffsetStruct *elementOffsetTablePtr);
int BufferToStructure (void *bufferPtr, unsigned int bufferSize,
void *structurePtr,
ElementOffsetStruct *elementOffsetTablePtr);
// End of StructureToBuffer.h