A lot of communication is done by creating packets (for sockets/IPC etc). Often you end up with variable sized packets for example strings in it. For example.
Then the name comes after the struct. If you do a class of thisCode:struct StringPacketBase { protected:int stringLen;};
I wonder if there is a better way to automate packet creation classes. Also a problem is that the string will never show up in debugging information.Code:class StringPacket : public StringPacketBase { public:uint getLength { return stringLen; } char *GetString { return (char*)this + sizeof(StringPacketBase) }};
I've seen this:
Now string is a part of the struct but what happens if you want two strings after each other? Then this method only work for the first string. Also if you use sizeof with StringPacketBase you have to be more careful now.Code:struct StringPacketBase { protected:int stringLen; char string[];};
The question is how you can create packets so that it becomes easy to write. Right now you do a lot of calculations with offsets and I wonder if there is a method make writing all these packets (which is a lot packets) more conveniently.



3Likes
LinkBack URL
About LinkBacks



