3 This file is part of gldbg
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
10 #include "functions.h"
11 #include "gldecoder.h"
13 static unsigned read_short(short *, const char *);
14 static unsigned read_int(int *, const char *);
15 static int decode_func(GlDecoder *, short, const char *);
17 GlDecoder *gldecoder_new(void *user_data, void (*destroy)(void *))
21 dec = (GlDecoder *)malloc(sizeof(GlDecoder));
22 memset(dec, 0, sizeof(GlDecoder));
23 dec->user_data = user_data;
24 dec->destroy = destroy;
29 void gldecoder_delete(GlDecoder *dec)
32 dec->destroy(dec->user_data);
36 int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len)
43 if(len<sizeof(int)+sizeof(short))
45 pos += read_int(&pktlen, data);
48 pos += read_short(&func, data+pos);
51 ret = decode_func(dec, func, data+pos);
58 static unsigned read_char(char *v, const char *data)
64 static unsigned read_short(short *v, const char *data)
70 static unsigned read_int(int *v, const char *data)
76 static unsigned read_long(long *v, const char *data)
82 static unsigned read_ulong(unsigned long *v, const char *data)
84 *v = *(unsigned long *)data;
85 return sizeof(unsigned long);
88 static unsigned read_longlong(long long *v, const char *data)
90 *v = *(long long *)data;
91 return sizeof(long long);
94 static unsigned read_float(float *v, const char *data)
100 static unsigned read_double(double *v, const char *data)
102 *v = *(double *)data;
103 return sizeof(double);
106 static unsigned read_pointer(void **v, const char *data)
109 return sizeof(void *);
112 static unsigned read_data(const void **v, const char *data)
116 pos += read_int(&vlen, data);
124 static unsigned read_string(const unsigned char **v, const char *data)
126 return read_data((const void **)v, data);
129 #include "gldecoder.funcs"