E
erbm
hello guys. I'm trying to converting a struct to a buffer of bytes, to
send to a server using sockets... I tryed a lot of solutions, but
nothing worked. I can convert the struct to a char* (string
representation) , but that isn't the point... I must send bytes to the
server and he must be able to deserialize the information. The
functions:
//return the number of alocated bytes
int message_to_buffer(struct message_t *msg, char **buffer);
//Deserialize the struct
struct message_t *buffer_to_message(int buflen, char *buffer);
the seralization should be something like this: (an array of bytes)
OPCODE KEYSIZE KEY DATASIZE DATA
[2byte] [4byte] [KEYSIZE bytes] [4 byte] [DATASIZE bytes]
And the structs:
struct message_t {
short opcode;
struct key_t key;
struct data_t data;
};
struct key_t{
int keysize;
char *key;
};
struct data_t{
int datasize;
char *data;
};
Does anyone have an ideia, how I can do that?
thanks
send to a server using sockets... I tryed a lot of solutions, but
nothing worked. I can convert the struct to a char* (string
representation) , but that isn't the point... I must send bytes to the
server and he must be able to deserialize the information. The
functions:
//return the number of alocated bytes
int message_to_buffer(struct message_t *msg, char **buffer);
//Deserialize the struct
struct message_t *buffer_to_message(int buflen, char *buffer);
the seralization should be something like this: (an array of bytes)
OPCODE KEYSIZE KEY DATASIZE DATA
[2byte] [4byte] [KEYSIZE bytes] [4 byte] [DATASIZE bytes]
And the structs:
struct message_t {
short opcode;
struct key_t key;
struct data_t data;
};
struct key_t{
int keysize;
char *key;
};
struct data_t{
int datasize;
char *data;
};
Does anyone have an ideia, how I can do that?
thanks