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");
}
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");
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");
}
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");
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);