[dev] network protocol packing

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Mon, 30 Jun 2014 20:54:52 +0200

Heyho,

since I did not find any suckless project regarding this issue, I would like to
ask you guys for some feedback:


unsigned char *msg;
size_t msg_size;
struct foo *msg_data;
struct bar *msg_signature;

msg_size = sizeof(unsigned char) // op
        + sizeof(struct foo) // data
        + sizeof(struct bar) // signature
msg = malloc(msg_size);

*msg = MSG_OP_SIGNED_DATA;

msg_data = (struct foo *)(msg + 1);
msg_data->field0 = bla;
msg_data->field1 = blub;

msg_signature = (struct bar *)(msg_data + 1);
create_signature(msg, msg_signature);

sendmsg(msg);

free(msg);


I feel it is pretty good already compared to other message packing I've seen,
but do you know a way to make it suck even less?

--Markus
Received on Mon Jun 30 2014 - 20:54:52 CEST

This archive was generated by hypermail 2.3.0 : Mon Jun 30 2014 - 21:00:08 CEST