msgbuf: Define a separate msgbuf structure for encode/decode function
Define separate msgbuf structures to avoid casting away const-qualifiers
in the msgbuf constructor function:
* pldm_msgbuf_rw: for encode functions with non const-qualified buffer
* pldm_msgbuf_ro: for decode functions with const-qualified buffer
Further, use _Generic() to keep the API ergonomic while still yielding a
compile error when wrong msgbuf type is passed.
Change-Id: I71dbcb7996e9fb402b49870fce539a939c1497e5
Signed-off-by: John Chung <john.chung@arm.com>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/tests/oem/meta/fileio.cpp b/tests/oem/meta/fileio.cpp
index 747f3be..845f0da 100644
--- a/tests/oem/meta/fileio.cpp
+++ b/tests/oem/meta/fileio.cpp
@@ -1,19 +1,21 @@
/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
+
+#include "msgbuf.hpp"
+
#include <endian.h>
+#include <libpldm/base.h>
#include <libpldm/oem/meta/file_io.h>
#include <cstdlib>
#include <new>
-#include "msgbuf.h"
-
#include "gmock/gmock.h"
#include <gtest/gtest.h>
TEST(DecodeOemMetaFileIoWriteReq, testGoodDecodeRequest)
{
constexpr const uint8_t postCode[4] = {0x93, 0xe0, 0x00, 0xea};
- PLDM_MSGBUF_DEFINE_P(ctx);
+ PLDM_MSGBUF_RW_DEFINE_P(ctx);
int rc;
constexpr size_t encodedPayloadLen =
@@ -82,7 +84,7 @@
TEST(DecodeOemMetaFileIoReadReq, testGoodDecodeRequest)
{
- PLDM_MSGBUF_DEFINE_P(ctx);
+ PLDM_MSGBUF_RW_DEFINE_P(ctx);
int rc;
constexpr size_t payloadLen = PLDM_OEM_META_FILE_IO_READ_REQ_MIN_LENGTH +