--- /dev/null
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009 Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "functions.h"
+#include "gldecoder.h"
+
+GlDecoder *gldecoder_new(void *user_data, void (*destroy)(void *))
+{
+ GlDecoder *dec;
+
+ dec = (GlDecoder *)malloc(sizeof(GlDecoder));
+ memset(dec, 0, sizeof(GlDecoder));
+ dec->user_data = user_data;
+ dec->destroy = destroy;
+
+ return dec;
+}
+
+void gldecoder_delete(GlDecoder *dec)
+{
+ if(dec->destroy)
+ dec->destroy(dec->user_data);
+ 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)
+{
+ *v = *(int *)data;
+ return sizeof(int);
+}
+
+unsigned read_long(long *v, const char *data, unsigned len)
+{
+ *v = *(long *)data;
+ return sizeof(long);
+}
+
+unsigned read_ulong(unsigned long *v, const char *data, unsigned len)
+{
+ *v = *(unsigned long *)data;
+ return sizeof(unsigned long);
+}
+
+unsigned read_longlong(long long *v, const char *data, unsigned len)
+{
+ *v = *(long long *)data;
+ return sizeof(long long);
+}
+
+unsigned read_float(float *v, const char *data, unsigned len)
+{
+ *v = *(float *)data;
+ return sizeof(float);
+}
+
+unsigned read_double(double *v, const char *data, unsigned len)
+{
+ *v = *(double *)data;
+ return sizeof(double);
+}
+
+unsigned read_pointer(void **v, const char *data, unsigned len)
+{
+ *v = *(void **)data;
+ return sizeof(void *);
+}
+
+unsigned read_data(const void **v, const char *data, unsigned len)
+{
+ int vlen;
+ unsigned pos = 0;
+ pos += read_int(&vlen, data, len);
+ *v = data+pos;
+ return pos+vlen;
+}
+
+unsigned read_string(const unsigned char **v, const char *data, unsigned len)
+{
+ return read_data((const void **)v, data, len);
+}
+
+#include "gldecoder.funcs"