Hi!
I'm trying to learn some network programming and right now im designing the package layout.
I think ill do it like this:
- first two bytes (an int): the size of the package
- third byte: the type of the package
- the rest: the data
The problem is that i dont know how to access a singe byte in a memblock created by malloc.
I guess i could use an unsiged char, but I'd like my app to be cross platform, and im not sure that a char is one byte on every arch.
Something like this:
Thanks!
I'm trying to learn some network programming and right now im designing the package layout.
I think ill do it like this:
- first two bytes (an int): the size of the package
- third byte: the type of the package
- the rest: the data
The problem is that i dont know how to access a singe byte in a memblock created by malloc.
I guess i could use an unsiged char, but I'd like my app to be cross platform, and im not sure that a char is one byte on every arch.
Something like this:
Code:
unsigned int packageSize = 2 + 1 + dataSize; unsiged char* package = (unsiged char*)malloc(packageSize); package[0] = (unsigned char)packageSize; package[2] = 2 // 2 being some predefined type memcpy(package[3], data, dataSize);
Comment