Simplify encode/decode for PLDM platform commands

The encode/decode for PLDM platform commands was implemented
using extensive pointer arithmetic and memcpys. To reduce the
pointer usage and also for the simple assignments, structures
have been created for each of the PLDM platform commands.

Change-Id: I6cf1a4b67b7a50325d2a2845245d937d71e13cb7
Signed-off-by: Priyanga <priyram1@in.ibm.com>
diff --git a/libpldm/platform.c b/libpldm/platform.c
index cfd72d4..d0929d9 100644
--- a/libpldm/platform.c
+++ b/libpldm/platform.c
@@ -44,13 +44,12 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	uint8_t *encoded_msg = msg->payload;
+	struct pldm_set_state_effecter_states_req *request =
+	    (struct pldm_set_state_effecter_states_req *)msg->payload;
 	effecter_id = htole16(effecter_id);
-	memcpy(encoded_msg, &effecter_id, sizeof(effecter_id));
-	encoded_msg += sizeof(effecter_id);
-	memcpy(encoded_msg, &comp_effecter_count, sizeof(comp_effecter_count));
-	encoded_msg += sizeof(comp_effecter_count);
-	memcpy(encoded_msg, field,
+	request->effecter_id = effecter_id;
+	request->comp_effecter_count = comp_effecter_count;
+	memcpy(request->field, field,
 	       (sizeof(set_effecter_state_field) * comp_effecter_count));
 
 	return PLDM_SUCCESS;
@@ -88,10 +87,12 @@
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
-	*effecter_id = le16toh(*((uint16_t *)msg));
-	*comp_effecter_count = *(msg + sizeof(*effecter_id));
-	memcpy(field,
-	       (msg + sizeof(*effecter_id) + sizeof(*comp_effecter_count)),
+	struct pldm_set_state_effecter_states_req *request =
+	    (struct pldm_set_state_effecter_states_req *)msg;
+
+	*effecter_id = le16toh(request->effecter_id);
+	*comp_effecter_count = request->comp_effecter_count;
+	memcpy(field, request->field,
 	       (sizeof(set_effecter_state_field) * (*comp_effecter_count)));
 
 	return PLDM_SUCCESS;
diff --git a/libpldm/platform.h b/libpldm/platform.h
index a5bfe4e..790f1f5 100644
--- a/libpldm/platform.h
+++ b/libpldm/platform.h
@@ -32,6 +32,16 @@
 	uint8_t effecter_state; //!< Expected state of the effecter
 } __attribute__((packed)) set_effecter_state_field;
 
+/** @struct PLDM_SetStateEffecterStates_Request
+ *
+ *  Structure representing PLDM set state effecter states request.
+ */
+struct pldm_set_state_effecter_states_req {
+	uint16_t effecter_id;
+	uint8_t comp_effecter_count;
+	set_effecter_state_field field[8];
+} __attribute__((packed));
+
 /* Responder */
 
 /* SetStateEffecterStates */