dsp: file: 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_file_df_open_req()
- encode_pldm_file_df_close_req()
- encode_pldm_file_df_heartbeat_req()
[1]: https://github.com/openbmc/libpldm/blob/main/CONTRIBUTING.md?plain=1#L270-L272
Change-Id: Ic81327438190bfa0541333f35e0b52a51010db91
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
diff --git a/src/dsp/file.c b/src/dsp/file.c
index 988d284..bdfc9c6 100644
--- a/src/dsp/file.c
+++ b/src/dsp/file.c
@@ -16,7 +16,7 @@
LIBPLDM_ABI_TESTING
int encode_pldm_file_df_open_req(uint8_t instance_id,
const struct pldm_file_df_open_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;
@@ -37,7 +37,7 @@
}
rc = pldm_msgbuf_init_errno(buf, PLDM_DF_OPEN_REQ_BYTES, msg->payload,
- payload_length);
+ *payload_length);
if (rc) {
return rc;
}
@@ -45,7 +45,7 @@
pldm_msgbuf_insert(buf, req->file_identifier);
pldm_msgbuf_insert(buf, req->file_attribute.value);
- return pldm_msgbuf_complete(buf);
+ return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
}
LIBPLDM_ABI_TESTING
@@ -147,7 +147,7 @@
LIBPLDM_ABI_TESTING
int encode_pldm_file_df_close_req(uint8_t instance_id,
const struct pldm_file_df_close_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;
@@ -168,7 +168,7 @@
}
rc = pldm_msgbuf_init_errno(buf, PLDM_DF_CLOSE_REQ_BYTES, msg->payload,
- payload_length);
+ *payload_length);
if (rc) {
return rc;
}
@@ -176,7 +176,7 @@
pldm_msgbuf_insert(buf, req->file_descriptor);
pldm_msgbuf_insert(buf, req->df_close_options.value);
- return pldm_msgbuf_complete(buf);
+ return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
}
LIBPLDM_ABI_TESTING
@@ -254,7 +254,7 @@
LIBPLDM_ABI_TESTING
int encode_pldm_file_df_heartbeat_req(
uint8_t instance_id, const struct pldm_file_df_heartbeat_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;
@@ -275,7 +275,7 @@
}
rc = pldm_msgbuf_init_errno(buf, PLDM_DF_HEARTBEAT_REQ_BYTES,
- msg->payload, payload_length);
+ msg->payload, *payload_length);
if (rc) {
return rc;
}
@@ -283,7 +283,7 @@
pldm_msgbuf_insert(buf, req->file_descriptor);
pldm_msgbuf_insert(buf, req->requester_max_interval);
- return pldm_msgbuf_complete(buf);
+ return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
}
LIBPLDM_ABI_TESTING