msgbuf: Add pldm_msgbuf_extract_array() for uint8
This is required for converting the
decode_get_pdr_repository_info_resp() function to pldm_msgbuf.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: If9afcaa83872969bcf8e4d0ecdeae2971e12248b
diff --git a/src/msgbuf.h b/src/msgbuf.h
index 551ce46..bf59388 100644
--- a/src/msgbuf.h
+++ b/src/msgbuf.h
@@ -285,6 +285,40 @@
: pldm_msgbuf_extract_int32, real32_t \
: pldm_msgbuf_extract_real32)(ctx, dst)
+static inline int pldm_msgbuf_extract_array_uint8(struct pldm_msgbuf *ctx,
+ uint8_t *dst, size_t count)
+{
+ size_t len;
+
+ if (!ctx || !ctx->cursor || !dst) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (!count) {
+ return PLDM_SUCCESS;
+ }
+
+ len = sizeof(*dst) * count;
+ if (len > SSIZE_MAX) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ ctx->remaining -= (ssize_t)len;
+ assert(ctx->remaining >= 0);
+ if (ctx->remaining < 0) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ memcpy(dst, ctx->cursor, len);
+ ctx->cursor += len;
+
+ return PLDM_SUCCESS;
+}
+
+#define pldm_msgbuf_extract_array(ctx, dst, count) \
+ _Generic((*(dst)), uint8_t \
+ : pldm_msgbuf_extract_array_uint8)(ctx, dst, count)
+
#ifdef __cplusplus
}
#endif