X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgldecoder.c;h=999acccc9cec140d141f5db97f878af136282cdf;hb=fab9ed5163a8f4ef5314bc67e48d1690d1126649;hp=93a525876c64c4b033bb92cd6f770239fcbc2dd9;hpb=9d1825d591a7261b1cff620ba535d333352984bf;p=gldbg.git diff --git a/source/gldecoder.c b/source/gldecoder.c index 93a5258..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,6 +9,10 @@ Distributed under the GPL #include #include "functions.h" #include "gldecoder.h" +#include "packet.h" + +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 *)) { @@ -29,72 +33,48 @@ void gldecoder_delete(GlDecoder *dec) free(dec); } -unsigned read_char(char *v, const char *data, unsigned len) -{ - *v = *data; - return 1; -} - -unsigned read_short(short *v, const char *data, unsigned len) -{ - *v = *(short *)data; - return sizeof(short); -} - -unsigned read_int(int *v, const char *data, unsigned len) +int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len) { - *v = *(int *)data; - return sizeof(int); -} + GlPacket *pkt; + unsigned short func; -unsigned read_long(long *v, const char *data, unsigned len) -{ - *v = *(long *)data; - return sizeof(long); -} + pkt = packet_receive_str(data, &len); + if(!pkt) + return -1; -unsigned read_ulong(unsigned long *v, const char *data, unsigned len) -{ - *v = *(unsigned long *)data; - return sizeof(unsigned long); -} + packet_read_short(pkt, (short *)&func); -unsigned read_longlong(long long *v, const char *data, unsigned len) -{ - *v = *(long long *)data; - return sizeof(long long); -} + if(dec) + { + int ret = 0; -unsigned read_float(float *v, const char *data, unsigned len) -{ - *v = *(float *)data; - return sizeof(float); -} + if(func&0x8000) + ret = decode_gldfunc(dec, func, pkt); + else + ret = decode_func(dec, func, pkt); + if(ret<0) + return -1; + } -unsigned read_double(double *v, const char *data, unsigned len) -{ - *v = *(double *)data; - return sizeof(double); + return len; } -unsigned read_pointer(void **v, const char *data, unsigned len) -{ - *v = *(void **)data; - return sizeof(void *); -} +#include "gensrc/gldecoder.funcs" -unsigned read_data(const void **v, const char *data, unsigned len) +static void decode_gldError(GlDecoder *dec, GlPacket *pkt) { - int vlen; - unsigned pos = 0; - pos += read_int(&vlen, data, len); - *v = data+pos; - return pos+vlen; + GLenum code; + packet_read_int(pkt, (int *)&code); + if(dec->gldError) + dec->gldError(dec->user_data, code); } -unsigned read_string(const unsigned char **v, const char *data, unsigned len) +static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt) { - return read_data((const void **)v, data, len); + switch(func) + { + case FUNC_GLDERROR: decode_gldError(dec, pkt); break; + default: return -1; + } + return 0; } - -#include "gldecoder.funcs"