OK, please bear with me and forgive my poor explanation on this, but here goes...
I have 20 different frame types of binary data which is just an array of bytes. Each frame is about 2000 bytes long.
Each frame has a mixture of 16 and 32 bit Ints and UInts which need to be extracted and then multiplied by an LSB to produce either a Single, Double, UInt, or Int data output value.
The first 2 bytes define the type of data in the frame so I can tell how and what position to pull the variables out.
Right now I have thousands of subroutines which use BitConverter.ToInt16, .ToInt32, .ToUInt16 and .ToUInt32 passing in the byte array and position in the array. Then I take the BitConverter output and multiply by an LSB and return the correct data type (Double, Int, UInt)
I would like to create a data dictionary which allows me to handle the data by reading the dictionary the software adapts accordingly.
Example :
One parameter I have in block 10 is an Int32 time in milliseconds at array position 0. The software calls a function with the byte array parameter. The function does a call to Bitconverter.ToInt32(byteArray, 0), then the data is multiplied by .001 and the function returns a Double.
I would like to change this to get the information out of a dictionary. Maybe store the offset into the byte array, LSB of the data, TypeOf BitConverter??, and maybe the return type.
I know I could also make about a dozen functions (numbers 1-12) and store this number in the dictionary. Then have a switch statement which would pick the correct function. For instance one uses BitConverter.ToInt32 returns a Double, one that uses BitConverter.ToUInt16 returns a UInt16, one that uses BitConverter.ToUInt16 that returns a Double, etc, etc. This is my fallback idea, but I think there may be more efficient ways.
I am processing about 20,000 parameters per second so I need for this to be fast.