-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstructpack.h
More file actions
39 lines (30 loc) · 899 Bytes
/
Copy pathstructpack.h
File metadata and controls
39 lines (30 loc) · 899 Bytes
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
#ifndef __STRUCTPACK_H__
#define __STRUCTPACK_H__
#include <stdint.h>
#include <stdarg.h>
class StructPack {
uint8_t* buffer;
uint32_t pos, maxLen;
const char* format;
va_list arg;
public:
StructPack(const char* format, va_list inArg);
StructPack(const char* format, va_list inArg, void* buffer, uint32_t maxLen);
~StructPack();
int doPack();
int doUnpack();
static int pack(void* buffer, uint32_t maxLen, const char* format, ...);
static int unpack(const void* buffer, uint32_t maxLen, const char* format, ...);
private:
void pack_uint8(uint8_t val);
void pack_uint32(uint32_t val);
void pack_float(float val);
void pack_string(const char* str, int len, int width);
void emit(uint8_t byte);
void unpack_uint8(uint8_t* val);
void unpack_uint32(uint32_t* val);
void unpack_float(float* val);
void unpack_string(char* str, int len, int width);
uint8_t fetch();
};
#endif