X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgldecoder.c;h=999acccc9cec140d141f5db97f878af136282cdf;hb=fab9ed5163a8f4ef5314bc67e48d1690d1126649;hp=85d089d2034af846d3d7c990db52db680d40ea66;hpb=0cdc7b50b0e7758a1660c94be664a810504a88f4;p=gldbg.git diff --git a/source/gldecoder.c b/source/gldecoder.c index 85d089d..999accc 100644 --- a/source/gldecoder.c +++ b/source/gldecoder.c @@ -1,7 +1,7 @@ /* $Id$ This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ @@ -9,10 +9,10 @@ Distributed under the GPL #include #include "functions.h" #include "gldecoder.h" +#include "packet.h" -static unsigned read_short(short *, const char *); -static unsigned read_int(int *, const char *); -static int decode_func(GlDecoder *, short, const char *); +static int decode_func(GlDecoder *, unsigned short, GlPacket *); +static int decode_gldfunc(GlDecoder *, unsigned short, GlPacket *); GlDecoder *gldecoder_new(void *user_data, void (*destroy)(void *)) { @@ -35,92 +35,46 @@ void gldecoder_delete(GlDecoder *dec) int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len) { - unsigned pos = 0; - int pktlen; - short func; - int ret; + GlPacket *pkt; + unsigned short func; - if(lengldError) + dec->gldError(dec->user_data, code); } -static unsigned read_float(float *v, const char *data) +static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt) { - *v = *(float *)data; - return sizeof(float); + switch(func) + { + case FUNC_GLDERROR: decode_gldError(dec, pkt); break; + default: return -1; + } + return 0; } - -static unsigned read_double(double *v, const char *data) -{ - *v = *(double *)data; - return sizeof(double); -} - -static unsigned read_pointer(void **v, const char *data) -{ - *v = *(void **)data; - return sizeof(void *); -} - -static unsigned read_data(const void **v, const char *data) -{ - int vlen; - unsigned pos = 0; - pos += read_int(&vlen, data); - if(vlen) - *v = data+pos; - else - *v = NULL; - return pos+vlen; -} - -static unsigned read_string(const unsigned char **v, const char *data) -{ - return read_data((const void **)v, data); -} - -#include "gldecoder.funcs"