Union discriminator value for default, invalid and fall-through cases

1 post / 0 new
Offline
Last seen: 6 months 3 weeks ago
Joined: 10/23/2013
Posts: 43
Union discriminator value for default, invalid and fall-through cases

I am using the Dyanamic Data API's to send/receive toipcs with unions.  I have 3 questions about the proper way to handle the discriminator value when read/take a sample that contains a union. The descriminator value is needed in order for the data reader application code to know which field in the union data structure has valid data.

1. Consider the following example for a union with a default case.  If the transmitted message has discrimnator is default (STATE_4), what will the discriminator be in the received sample? Is there a way to figure out that the discrimnator is representing the default case?

enum EnumState
{
STATE_1 = 10,
STATE_2 = 20,
STATE_3 = 30,
STATE_4 = 40,
STATE_5 = 50
};

union UnionStructDef switch (EnumState)
{
case STATE_1 : long USD_Long;
default : short US_Short;
case STATE_3 : char US_Char;

};

2.  The following union does not have a default state.   If the transmitted message has discrimnator = STATE_4, what will the discriminator be in the received sample? Is there a way to figure out that an invalid discrimnator was sent?

union UnionStruct switch (EnumState) 
{
case STATE_1 : long USD_Long;
case STATE_2 : short US_Short;
case STATE_3 : char US_Char;

};

3.  The following union has multiple cases used for the same payload.   If the transmitted message has discrimnator = STATE_3, what will the discriminator be in the received sample?   If transmitted message is STATE_4?

union UnionStruct switch (EnumState) 
{
case STATE_1 : long USD_Long;
case STATE_2 : short US_Short;
case STATE_3 : 
case STATE_4 : char US_Char;
};

 

 

 

Organization: