dsp: base: Let some encode APIs accept pointer to payload_length

In order to achieve [1], this commit updates some encoding APIs to
accept the length of the message as an in/out parameter (pointer to
size_t). The APIs are then updated to return the encoded payload length
through this parameter.

The unit tests for these APIs are updated accordingly. The change list
includes:

  - encode_pldm_base_multipart_receive_req()
  - encode_pldm_base_negotiate_transfer_params_req()

[1]: https://github.com/openbmc/libpldm/blob/main/CONTRIBUTING.md?plain=1#L270-L272

Change-Id: I17cb3641b2c4a7a30fe757a3275b1713499484cc
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
diff --git a/src/dsp/base.c b/src/dsp/base.c
index c8a9210..c227beb 100644
--- a/src/dsp/base.c
+++ b/src/dsp/base.c
@@ -585,12 +585,12 @@
 LIBPLDM_ABI_TESTING
 int encode_pldm_base_multipart_receive_req(
 	uint8_t instance_id, const struct pldm_base_multipart_receive_req *req,
-	struct pldm_msg *msg, size_t payload_length)
+	struct pldm_msg *msg, size_t *payload_length)
 {
 	PLDM_MSGBUF_DEFINE_P(buf);
 	int rc;
 
-	if (req == NULL || msg == NULL) {
+	if (req == NULL || msg == NULL || payload_length == NULL) {
 		return -EINVAL;
 	}
 
@@ -606,7 +606,7 @@
 	}
 
 	rc = pldm_msgbuf_init_errno(buf, PLDM_MULTIPART_RECEIVE_REQ_BYTES,
-				    msg->payload, payload_length);
+				    msg->payload, *payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -618,7 +618,7 @@
 	pldm_msgbuf_insert(buf, req->section_offset);
 	pldm_msgbuf_insert(buf, req->section_length);
 
-	return pldm_msgbuf_complete(buf);
+	return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
 }
 
 LIBPLDM_ABI_TESTING
@@ -795,12 +795,12 @@
 int encode_pldm_base_negotiate_transfer_params_req(
 	uint8_t instance_id,
 	const struct pldm_base_negotiate_transfer_params_req *req,
-	struct pldm_msg *msg, size_t payload_length)
+	struct pldm_msg *msg, size_t *payload_length)
 {
 	PLDM_MSGBUF_DEFINE_P(buf);
 	int rc;
 
-	if (req == NULL || msg == NULL) {
+	if (req == NULL || msg == NULL || payload_length == NULL) {
 		return -EINVAL;
 	}
 
@@ -817,7 +817,7 @@
 
 	rc = pldm_msgbuf_init_errno(
 		buf, PLDM_BASE_NEGOTIATE_TRANSFER_PARAMETERS_REQ_BYTES,
-		msg->payload, payload_length);
+		msg->payload, *payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -831,7 +831,7 @@
 		return pldm_msgbuf_discard(buf, rc);
 	}
 
-	return pldm_msgbuf_complete(buf);
+	return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
 }
 
 LIBPLDM_ABI_TESTING