Significant simplification of prvWriteMessageToBuffer

This commit is contained in:
Miles Frain 2021-02-22 22:48:26 -08:00
parent 0f3149e2a7
commit f6bd2e3aed

View file

@ -724,51 +724,40 @@ static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,
size_t xSpace,
size_t xRequiredSpace )
{
BaseType_t xShouldWrite;
size_t xReturn;
size_t xNextHead = pxStreamBuffer->xHead;
if( xSpace == ( size_t ) 0 )
if( xDataLengthBytes != xRequiredSpace )
{
/* Doesn't matter if this is a stream buffer or a message buffer, there
* is no space to write. */
xShouldWrite = pdFALSE;
/* This is a message buffer, as opposed to a stream buffer. */
if( xSpace >= xRequiredSpace )
{
/* There is enough space to write both the message length and the message
* itself into the buffer. Start by writing the length of the data, the data
* itself will be written later in this function. */
xNextHead = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH, xNextHead);
}
else
{
/* Not enough space, so do not write data to the buffer. */
xDataLengthBytes = 0;
}
}
else if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) == ( uint8_t ) 0 )
else
{
/* This is a stream buffer, as opposed to a message buffer, so writing a
* stream of bytes rather than discrete messages. Write as many bytes as
* possible. */
xShouldWrite = pdTRUE;
* stream of bytes rather than discrete messages. Plan to write as many
* bytes as possible. */
xDataLengthBytes = configMIN( xDataLengthBytes, xSpace );
}
else if( xSpace >= xRequiredSpace )
{
/* This is a message buffer, as opposed to a stream buffer, and there
* is enough space to write both the message length and the message itself
* into the buffer. Start by writing the length of the data, the data
* itself will be written later in this function. */
xShouldWrite = pdTRUE;
xNextHead = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH, xNextHead);
}
else
{
/* There is space available, but not enough space. */
xShouldWrite = pdFALSE;
}
if( xShouldWrite != pdFALSE )
if( xDataLengthBytes != ( size_t ) 0 )
{
/* Write the actual data and update the head to mark the data as officially written. */
/* Write the data to the buffer. */
pxStreamBuffer->xHead = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes, xNextHead ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alignment and access. */
xReturn = xDataLengthBytes;
}
else
{
xReturn = 0;
}
return xReturn;
return xDataLengthBytes;
}
/*-----------------------------------------------------------*/