]> git.lizzy.rs Git - dragonnet.git/commitdiff
Make CompressedBlob wrap Blob
authorHimbeerserverDE <himbeerserverde@gmail.com>
Sun, 10 Oct 2021 13:18:14 +0000 (15:18 +0200)
committerHimbeerserverDE <himbeerserverde@gmail.com>
Sun, 10 Oct 2021 13:18:14 +0000 (15:18 +0200)
typegen/main.c

index 5c00112675c7adf5f7d4903d42f82c76a8a122dc..575e019143076da9539b6dd47601a411c1a3ec68 100644 (file)
@@ -145,22 +145,22 @@ static void gen_serializers(FILE *c_fp)
 
        fprintf(c_fp, "__attribute__((unused)) static void send_CompressedBlob(DragonnetPeer *p, bool submit, CompressedBlob v)\n\n");
        fprintf(c_fp, "{\n");
-       fprintf(c_fp, "\tchar compr[2 + v->siz];\n\n");
+       fprintf(c_fp, "\tchar compr[2 + v->blob->siz];\n\n");
        fprintf(c_fp, "\tz_stream s;\n");
        fprintf(c_fp, "\ts.zalloc = Z_NULL;\n");
        fprintf(c_fp , "\ts.zfree = Z_NULL;\n");
        fprintf(c_fp, "\ts.opaque = Z_NULL;\n\n");
-       fprintf(c_fp, "\ts.avail_in = v->siz;\n");
-       fprintf(c_fp, "\ts.avail_out = 3 + v->siz;\n");
-       fprintf(c_fp, "\ts.next_in = (Bytef *) v->data;\n");
+       fprintf(c_fp, "\ts.avail_in = v->blob->siz;\n");
+       fprintf(c_fp, "\ts.avail_out = 3 + v->blob->siz;\n");
+       fprintf(c_fp, "\ts.next_in = (Bytef *) v->blob->data;\n");
        fprintf(c_fp, "\ts.next_out = (Bytef *) compr;\n\n");
        fprintf(c_fp, "\tdeflateInit(&s, Z_BEST_COMPRESSION);\n");
        fprintf(c_fp, "\tdeflate(&s, Z_FINISH);\n");
        fprintf(c_fp, "\tdeflateEnd(&s);\n\n");
-       fprintf(c_fp, "\tv->compr_siz = s.total_out;\n");
-       fprintf(c_fp, "\tsend_u32(p, false, v->compr_siz);\n");
+       fprintf(c_fp, "\tv->siz = s.total_out;\n");
        fprintf(c_fp, "\tsend_u32(p, false, v->siz);\n");
-       fprintf(c_fp, "\tdragonnet_send_raw(p, submit, compr, v->compr_siz);\n");
+       fprintf(c_fp, "\tsend_u32(p, false, v->blob->siz);\n");
+       fprintf(c_fp, "\tdragonnet_send_raw(p, submit, compr, v->siz);\n");
        fprintf(c_fp, "}\n\n");
 }
 
@@ -226,19 +226,20 @@ static void gen_deserializers(FILE *c_fp)
        fprintf(c_fp, "__attribute__((unused)) static void recv_CompressedBlob(DragonnetPeer *p, void *buf)\n");
        fprintf(c_fp, "{\n");
        fprintf(c_fp, "\tCompressedBlob v = *(CompressedBlob *) buf;\n");
-       fprintf(c_fp, "\trecv_n32(p, &v->compr_siz);\n");
+       fprintf(c_fp, "\tv->blob = malloc(sizeof *v->blob);\n\n");
        fprintf(c_fp, "\trecv_n32(p, &v->siz);\n");
-       fprintf(c_fp, "\tv->data = malloc(v->siz);\n\n");
-       fprintf(c_fp, "\tchar compr[v->compr_siz];\n");
+       fprintf(c_fp, "\trecv_n32(p, &v->blob->siz);\n");
+       fprintf(c_fp, "\tv->blob->data = malloc(v->blob->siz);\n\n");
+       fprintf(c_fp, "\tchar compr[v->siz];\n");
        fprintf(c_fp, "\tdragonnet_recv_raw(p, compr, sizeof compr);\n\n");
        fprintf(c_fp, "\tz_stream s;\n");
        fprintf(c_fp, "\ts.zalloc = Z_NULL;\n");
        fprintf(c_fp, "\ts.zfree = Z_NULL;\n");
        fprintf(c_fp, "\ts.opaque = Z_NULL;\n\n");
-       fprintf(c_fp, "\ts.avail_in = v->compr_siz;\n");
+       fprintf(c_fp, "\ts.avail_in = v->siz;\n");
        fprintf(c_fp, "\ts.next_in = (Bytef *) compr;\n");
-       fprintf(c_fp, "\ts.avail_out = v->siz;\n");
-       fprintf(c_fp, "\ts.next_out = (Bytef *) v->data;\n\n");
+       fprintf(c_fp, "\ts.avail_out = v->blob->siz;\n");
+       fprintf(c_fp, "\ts.next_out = (Bytef *) v->blob->data;\n\n");
        fprintf(c_fp, "\tinflateInit(&s);\n");
        fprintf(c_fp, "\tinflate(&s, Z_NO_FLUSH);\n");
        fprintf(c_fp, "\tinflateEnd(&s);\n");
@@ -357,22 +358,22 @@ static void gen_buffer_serializers(FILE *c_fp)
 
        fprintf(c_fp, "__attribute__((unused)) static void buf_write_CompressedBlob(u8 **buf, size_t *n, CompressedBlob v)\n\n");
        fprintf(c_fp, "{\n");
-       fprintf(c_fp, "\tchar compr[2 + v->siz];\n\n");
+       fprintf(c_fp, "\tchar compr[2 + v->blob->siz];\n\n");
        fprintf(c_fp, "\tz_stream s;\n");
        fprintf(c_fp, "\ts.zalloc = Z_NULL;\n");
        fprintf(c_fp , "\ts.zfree = Z_NULL;\n");
        fprintf(c_fp, "\ts.opaque = Z_NULL;\n\n");
-       fprintf(c_fp, "\ts.avail_in = v->siz;\n");
-       fprintf(c_fp, "\ts.avail_out = 3 + v->siz;\n");
-       fprintf(c_fp, "\ts.next_in = (Bytef *) v->data;\n");
+       fprintf(c_fp, "\ts.avail_in = v->blob->siz;\n");
+       fprintf(c_fp, "\ts.avail_out = 3 + v->blob->siz;\n");
+       fprintf(c_fp, "\ts.next_in = (Bytef *) v->blob->data;\n");
        fprintf(c_fp, "\ts.next_out = (Bytef *) compr;\n\n");
        fprintf(c_fp, "\tdeflateInit(&s, Z_BEST_COMPRESSION);\n");
        fprintf(c_fp, "\tdeflate(&s, Z_FINISH);\n");
        fprintf(c_fp, "\tdeflateEnd(&s);\n\n");
-       fprintf(c_fp, "\tv->compr_siz = s.total_out;\n");
-       fprintf(c_fp, "\tbuf_write_u32(buf, n, v->compr_siz);\n");
+       fprintf(c_fp, "\tv->siz = s.total_out;\n");
        fprintf(c_fp, "\tbuf_write_u32(buf, n, v->siz);\n");
-       fprintf(c_fp, "\tdragonnet_write_raw(buf, n, compr, v->compr_siz);\n");
+       fprintf(c_fp, "\tbuf_write_u32(buf, n, v->blob->siz);\n");
+       fprintf(c_fp, "\tdragonnet_write_raw(buf, n, compr, v->siz);\n");
        fprintf(c_fp, "}\n\n");
 }
 
@@ -510,19 +511,20 @@ static void gen_buffer_deserializers(FILE *c_fp)
        fprintf(c_fp, "__attribute__((unused)) static CompressedBlob buf_read_CompressedBlob(u8 **buf, size_t *n)\n");
        fprintf(c_fp, "{\n");
        fprintf(c_fp, "\tCompressedBlob v = malloc(sizeof *v);\n");
-       fprintf(c_fp, "\tv->compr_siz = buf_read_u32(buf, n);\n");
+       fprintf(c_fp, "\tv->blob = malloc(sizeof *v->blob);\n\n");
        fprintf(c_fp, "\tv->siz = buf_read_u32(buf, n);\n");
-       fprintf(c_fp, "\tv->data = malloc(v->siz);\n\n");
-       fprintf(c_fp, "\tchar compr[v->compr_siz];\n");
+       fprintf(c_fp, "\tv->blob->siz = buf_read_u32(buf, n);\n");
+       fprintf(c_fp, "\tv->blob->data = malloc(v->blob->siz);\n\n");
+       fprintf(c_fp, "\tchar compr[v->siz];\n");
        fprintf(c_fp, "\tdragonnet_read_raw(buf, n, compr, sizeof compr);\n\n");
        fprintf(c_fp, "\tz_stream s;\n");
        fprintf(c_fp, "\ts.zalloc = Z_NULL;\n");
        fprintf(c_fp, "\ts.zfree = Z_NULL;\n");
        fprintf(c_fp, "\ts.opaque = Z_NULL;\n\n");
-       fprintf(c_fp, "\ts.avail_in = v->compr_siz;\n");
+       fprintf(c_fp, "\ts.avail_in = v->siz;\n");
        fprintf(c_fp, "\ts.next_in = (Bytef *) compr;\n");
-       fprintf(c_fp, "\ts.avail_out = v->siz;\n");
-       fprintf(c_fp, "\ts.next_out = (Bytef *) v->data;\n\n");
+       fprintf(c_fp, "\ts.avail_out = v->blob->siz;\n");
+       fprintf(c_fp, "\ts.next_out = (Bytef *) v->blob->data;\n\n");
        fprintf(c_fp, "\tinflateInit(&s);\n");
        fprintf(c_fp, "\tinflate(&s, Z_NO_FLUSH);\n");
        fprintf(c_fp, "\tinflateEnd(&s);\n\n");
@@ -556,8 +558,8 @@ int main(__attribute((unused)) int argc, __attribute((unused)) char **argv)
        fprintf(h_fp, "typedef char *string;\n\n");
        fprintf(h_fp, "typedef struct {\n\tu32 siz;\n\tu8 *data;\n} *Blob;\n\n");
        fprintf(h_fp, "typedef struct {\n");
-       fprintf(h_fp, "\tu32 siz, compr_siz;\n");
-       fprintf(h_fp, "\tu8 *data;\n");
+       fprintf(h_fp, "\tu32 siz;\n");
+       fprintf(h_fp, "\tBlob blob;\n");
        fprintf(h_fp, "} *CompressedBlob;\n\n");
 
        gen_serializers(c_fp);