In the light_switch example of nRF5_SDK_for_Mesh_3.1.0, I noticed that generic_onoff_client.h has a union for holding the current message packet. However, there is only one member of type generic_onoff_set_msg_pkt_t in the union.
What is the reasoning for this? Isn't a union with one member the same as a struct with one member? Why would I use a union over a struct in this situation?
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// generic_onoff_client.h:
/** Union for holding current message packet */
typedef union
{
generic_onoff_set_msg_pkt_t set;
} generic_onoff_client_msg_data_t;
// generic_onoff_messages.h:
/** Message format for the generic_onoff Set message. */
typedef struct __attribute((packed))
{
uint8_t on_off; /**< State to set */
uint8_t tid; /**< Transaction number for application */
uint8_t transition_time; /**< Encoded transition time value */
uint8_t delay; /**< Encoded message execution delay in 5 millisecond steps */
} generic_onoff_set_msg_pkt_t;