X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgldecoder.c;h=f5540c09077930b0a1875031610df71008642dbb;hb=ea3d851aa52e999b1c5a5fa52c97ff5019756c0e;hp=e11d13c46d51ef0a064415eecf7933b7cb0e6b10;hpb=c6b2f7585d51164dc32f4dd2a05855913e464c58;p=gldbg.git diff --git a/source/gldecoder.c b/source/gldecoder.c index e11d13c..f5540c0 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,95 +35,49 @@ 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); -} - -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); + switch(func) + { + case FUNC_GLDERROR: decode_gldError(dec, pkt); break; + default: return -1; + } + return 0; } - -#include "gldecoder.funcs"