Introduce a structure to represent variable fields
Introduce a structure to represent variable fields

If there is a variable field in the message body, the decode function
needs to ensure that the buffer space passed by the caller is sufficient,
and then copy the contents of the field into the buffer.

However, we can do it like this:

struct variable_field{
         const uint8_t * ptr; // point to the filed in the message body
         size_t length; // length of the field
};

decode_func(request_msg, struct variable_field *field)

pldm command runs as request-response, we(openbmc) hold the request message
until command processing is complete. So in most cases, the lifecycle of
the message body is longer than the variable_field struct. then, it's no
need to copy the field, improving performance.

if we need to copy the field, we could:

uint8_t buffer[field->length]; // here we know exactly the size of the buffer
memcpy(buffer, field->ptr, filed->length);

avoid checking the buffer length in decode_functions().

eg:

decode_func(request_msg, uint8_t *buffer, size_t buffer_length)
{
	size_t field_length = sth;
	if(filed_length > buffer_length){
		do_sth;
	}
	memcpy(buffer, field, field_length);
}

uint8_t buffer[estimated];
decode_func(request_msg, buffer,sizeof(buffer));

In addition, s/breif/brief in the comments

Signed-off-by: John Wang <f94ba6c7f9f751e26d9bd16a9d1e9a602cdeac6b@inspur.com>
Change-Id: I033aa14edc2e93b0d6bb9e732e5259cf41e8cf75

openbmc/pldm,openbmc/pldm,openbmc/pldm