I figured the subject would get everyone's attention. So when dealing with sockets, you receive an array of unsigned char's, also known as bytes. One way to interpret data from those bytes is to make a class with all your needed fields (or struct, it doesn't matter), and do something like this:
- MyClass *translatedData = reinterpret_cast<MyClass*>(&rawBytesReceivedFromSocket);
Obviously this is not ideal. I have to check that the payload is sane before doing something like this. The bytes' structure has to line up with my class exactly. Also, something just doesn't sit well with me, when essentially I'm doing a c-style translation in c++ clothing (if that makes any sense). Not very secure either, treating raw-bytes this way.There has to be a better, OO way. Any ideas?
Joe