Hello!
I am writing a client to communicate with the device using the IEC 60870-5-104 protocol. In fact, that the protocol does not matter.
As a result of polling the server by the client, I get a package in which there is an address and there is a value. There is an address table in which the address indicates which parameter value (current, voltage, bit indication) is hidden under this address.
I create a class that describes the measuring device. Fields are measured values and bit indicators. When I receive the parcel, I extract the address from it and, at this very address, I can, looking in the table, determine what the value has been received.
The question is - how best to fill the class field when receiving the parcel? I have no connection between the field and the address in the program, that is, I clearly have to register at the moment, if Package.Address == 1, then Device.Voltage = Package.Value, for example, and there may be many such fields.
The most straightforward option to do through the switch-case in the manner indicated above.
I thought to create an enumeration in which to specify variables whose names are identical to the names of the class fields and assign them addresses from the table. Thus, a parcel arrives -> we look at the address in the enumeration -> we obtain from the enumeration the name of a variable -> by the name of the variable we determine in which field we write the value -> we write the value in the field (by name somehow ???)