I have a class in c++ named InformationElement which defines the following Information Element frame structure:
<-Element ID-> <-Element Length- ><-Variable Payload->
- The element ID is 1 Byte.
- The Element Length is 1 Byte Long. It defines the length of the payload part.
- The class contains virtual functions used for serialization and deserialziation of the contents + defining the type of the ElementID.
From this class different derived classes are inherited for example:
- class Capabilities
- class Operation.
- class TimingParameters.
Each of the derived class has a unique Element ID and different payload.
Different Information Elements (IEs) will be encapsulated in a bigger frame. This bigger frame contains the number of Information Elements that are encapsulated in it.
<-Number of IEs-> <--IE 1--> <-- IE 2 --> <-- IE 3 --> ......
From the transmitter point of view there is no problem in serializing these information. However, in the receiver side, the receiver has to extract the Element ID and based on that value the receiver chooses the correct derived class to handle the payload part i.e. handle the deserialization operation. The traditional way of doing this in the receiver side is to build a big switch case as following:
InformationElement *element;
switch (elementID)
{
case 1:
element = new Capabilties;
case 2:
element = new Operation;
case 3:
element = new TimingParameters;
}
However, if I have 100 elements, it would be too much to compare with and it won't scale that much.
So my question is there any smart way to do this in c++ better than inserting a unique case for each independent Element ID?