I am trying to implement a message that contains sub messages. The format would look something like the following.
Message: Field 1, field 2, ..., sub type, buffer
Depending on the sub type there could be one of several ways to interpret the buffer. Some of the sub messages might look something like the following.
Sub type 1: Field 1, field 2, ..., sub sub type
Sub sub type 1: Field 1, field 2, ..., data buffer
What I'm not sure about is how to structure my code in order to best represent the structure that exists. The sub messages don't inherit from each other, so I don't want to use inheritance.
Each of the fields represented in the message could be anywhere from 1 to 31 bits in length. Ideally I would like to have a struct/class with all unsigned int
data types to make it easy to interact with the data and let the serialize/deserialize methods handle packing and unpacking the data before/after sending/receiving the buffer on the network.
union
of structs (classes).