I'm trying to build a structure in VB to allow me to both store and parse an IP/UDP based message that I'm receiving as ASCII encoded HEX.
The trick is that after I get past the IP header and the UDP header the data that follows after is of a variable structure type. By that I mean that there is a basic initial message structure that has data in specific fields... two thirds of which are optional... but then the actual data, the real meat of the transmission, is in one of 15 different message structures.
So is there a way to conditionally define one of the members of the structure based on the data I'm putting in it?
My plan was to create a New() function that you could simply pass the message string to and it would parse out all of the data and populate the members of the structures as needed. But how can I make the declaration type of one of the structure members dependent on the data that will be parsed out in the New() function? Or is there no way to really do this?
Basically something (albeit crudely) like this:
Private Structure DevMsg
ReadOnly IPHeader As IP_HDR
ReadOnly UDPHeader As UDP_HDR
ReadOnly MsgType As DevMsgType
Select Case MsgType
Case Msg0
ReadOnly Data as MsgType0
Case Msg1
ReadOnly Data as MsgType1
...
End Select
Public Sub New(ByVal msg as String)
... String parser ...
MsgType = blah
... More parsing ...
Data.property0 = blah2
Data.property1 = blah3
...
End Sub
End Structure