Skip to content

Commit

Permalink
Adds structure initialization using named fields
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Pullin <[email protected]>
  • Loading branch information
apullin committed Jul 19, 2017
1 parent 1e7c337 commit 86269f9
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions MQTTPacket/src/MQTTConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ typedef struct
} MQTTPacket_willOptions;


#define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 }

#define MQTTPacket_willOptions_initializer \
{ \
.struct_id = {'M', 'Q', 'T', 'W'}, \
.struct_version = 0, \
.topicName = MQTTString_initializer, \
.message = MQTTString_initializer, \
.retained = 0, \
.qos = 0, \
}

typedef struct
{
Expand Down Expand Up @@ -122,9 +129,19 @@ typedef union
#endif
} MQTTConnackFlags; /**< connack flags byte */

#define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }

#define MQTTPacket_connectData_initializer \
{ \
.struct_id = {'M', 'Q', 'T', 'C'}, \
.struct_version = 0, \
.MQTTVersion = 4, \
.clientID = MQTTString_initializer, \
.keepAliveInterval = 60, \
.cleansession = 1, \
.willFlag = 0, \
.will = MQTTPacket_willOptions_initializer, \
.username = MQTTString_initializer, \
.password = MQTTString_initializer, \
}
DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options);
DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len);

Expand Down

0 comments on commit 86269f9

Please sign in to comment.