Decode APIs now accept const struct pldm_msg *msg

All the decode_xxx APIs were changed to accept the complete pldm_msg
instead of working with just a specific member (payload) making it
consistent with the encode_xxx APIs.

Following changes were made through out the code,
 - decode_xxx now requires to send the const struct pldm_msg *msg
   instead of a const uint8_t *msg.
 - Within the decode_xxx function the payload is extracted and used
   accordingly.
 - All the calls made to decode_xxx APIs have been modified to now
   pass the pointer to pldm_msg_hdr (struct pldm_msg *msg).
 - The test code was modified to now pass the appropriate data
   to all the encode_xxx APIs.

Change-Id: I16a3f6e554ea2c9fa44d55dc8f21f65022bd983a
Signed-off-by: Zahed Hossain <zahzahed@in.ibm.com>
diff --git a/test/libpldm_platform_test.cpp b/test/libpldm_platform_test.cpp
index b046e3f..1010bd8 100644
--- a/test/libpldm_platform_test.cpp
+++ b/test/libpldm_platform_test.cpp
@@ -7,6 +7,8 @@
 
 #include <gtest/gtest.h>
 
+constexpr auto hdrSize = sizeof(pldm_msg_hdr);
+
 TEST(SetStateEffecterStates, testEncodeResponse)
 {
     std::array<uint8_t,
@@ -56,17 +58,20 @@
 
 TEST(SetStateEffecterStates, testGoodDecodeResponse)
 {
-    std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
+    std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
         responseMsg{};
 
     uint8_t completion_code = 0xA0;
 
     uint8_t retcompletion_code = 0;
 
-    memcpy(responseMsg.data(), &completion_code, sizeof(completion_code));
+    memcpy(responseMsg.data() + hdrSize, &completion_code,
+           sizeof(completion_code));
+
+    auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
 
     auto rc = decode_set_state_effecter_states_resp(
-        responseMsg.data(), responseMsg.size(), &retcompletion_code);
+        response, responseMsg.size() - hdrSize, &retcompletion_code);
 
     ASSERT_EQ(rc, PLDM_SUCCESS);
     ASSERT_EQ(completion_code, retcompletion_code);
@@ -74,7 +79,8 @@
 
 TEST(SetStateEffecterStates, testGoodDecodeRequest)
 {
-    std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{};
+    std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
+        requestMsg{};
 
     uint16_t effecterId = 0x32;
     uint8_t compEffecterCnt = 0x2;
@@ -88,14 +94,17 @@
 
     std::array<set_effecter_state_field, 8> retStateField{};
 
-    memcpy(requestMsg.data(), &effecterId, sizeof(effecterId));
-    memcpy(requestMsg.data() + sizeof(effecterId), &compEffecterCnt,
+    memcpy(requestMsg.data() + hdrSize, &effecterId, sizeof(effecterId));
+    memcpy(requestMsg.data() + sizeof(effecterId) + hdrSize, &compEffecterCnt,
            sizeof(compEffecterCnt));
-    memcpy(requestMsg.data() + sizeof(effecterId) + sizeof(compEffecterCnt),
+    memcpy(requestMsg.data() + sizeof(effecterId) + sizeof(compEffecterCnt) +
+               hdrSize,
            &stateField, sizeof(stateField));
 
+    auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
     auto rc = decode_set_state_effecter_states_req(
-        requestMsg.data(), requestMsg.size(), &retEffecterId,
+        request, requestMsg.size() - hdrSize, &retEffecterId,
         &retCompEffecterCnt, retStateField.data());
 
     ASSERT_EQ(rc, PLDM_SUCCESS);
@@ -109,7 +118,7 @@
 
 TEST(SetStateEffecterStates, testBadDecodeRequest)
 {
-    const uint8_t* msg = NULL;
+    const struct pldm_msg* msg = NULL;
 
     auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL,
                                                    NULL, NULL);
@@ -122,7 +131,9 @@
     std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
         responseMsg{};
 
-    auto rc = decode_set_state_effecter_states_resp(responseMsg.data(),
+    auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+    auto rc = decode_set_state_effecter_states_resp(response,
                                                     responseMsg.size(), NULL);
 
     ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);