forked from cloudwu/sproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sproto.h
51 lines (38 loc) · 1.36 KB
/
sproto.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
#ifndef sproto_h
#define sproto_h
#include <stddef.h>
struct sproto;
struct sproto_type;
#define SPROTO_REQUEST 0
#define SPROTO_RESPONSE 1
#define SPROTO_TINTEGER 0
#define SPROTO_TBOOLEAN 1
#define SPROTO_TSTRING 2
#define SPROTO_TSTRUCT 3
struct sproto * sproto_create(const void * proto, size_t sz);
void sproto_release(struct sproto *);
int sproto_prototag(struct sproto *, const char * name);
const char * sproto_protoname(struct sproto *, int proto);
// SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response
struct sproto_type * sproto_protoquery(struct sproto *, int proto, int what);
struct sproto_type * sproto_type(struct sproto *, const char * type_name);
int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz);
int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz);
struct sproto_arg {
void *ud;
const char *tagname;
int tagid;
int type;
struct sproto_type *subtype;
void *value;
int length;
int index; // array base 1
int mainindex; // for map
};
typedef int (*sproto_callback)(const struct sproto_arg *args);
int sproto_decode(struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud);
int sproto_encode(struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud);
// for debug use
void sproto_dump(struct sproto *);
const char * sproto_name(struct sproto_type *);
#endif