Help - trying to serialize a struct
- From: erbm <edymont@xxxxxxxxx>
- Date: Mon, 30 Mar 2009 19:47:46 -0700 (PDT)
hello guys. I'm trying to convert 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 are:
//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
.
- Follow-Ups:
- Re: Help - trying to serialize a struct
- From: Mark Wooding
- Re: Help - trying to serialize a struct
- From: user923005
- Re: Help - trying to serialize a struct
- From: Gordon Burditt
- Re: Help - trying to serialize a struct
- Prev by Date: Re: C as a scripting language
- Next by Date: Re: Cannot find error on my program ( verry basic C stuff )
- Previous by thread: Re: Help - trying to serialize a struct
- Next by thread: Re: Help - trying to serialize a struct
- Index(es):
Relevant Pages
|