| 956 | /*-----------------------------------------------------------*/ |
| 957 | |
| 958 | static size_t prvReadMessageFromBuffer( StreamBuffer_t * pxStreamBuffer, |
| 959 | void * pvRxData, |
| 960 | size_t xBufferLengthBytes, |
| 961 | size_t xBytesAvailable, |
| 962 | size_t xBytesToStoreMessageLength ) |
| 963 | { |
| 964 | size_t xOriginalTail, xReceivedLength, xNextMessageLength; |
| 965 | configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength; |
| 966 | |
| 967 | if( xBytesToStoreMessageLength != ( size_t ) 0 ) |
| 968 | { |
| 969 | /* A discrete message is being received. First receive the length |
| 970 | * of the message. A copy of the tail is stored so the buffer can be |
| 971 | * returned to its prior state if the length of the message is too |
| 972 | * large for the provided buffer. */ |
| 973 | xOriginalTail = pxStreamBuffer->xTail; |
| 974 | ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable ); |
| 975 | xNextMessageLength = ( size_t ) xTempNextMessageLength; |
| 976 | |
| 977 | /* Reduce the number of bytes available by the number of bytes just |
| 978 | * read out. */ |
| 979 | xBytesAvailable -= xBytesToStoreMessageLength; |
| 980 | |
| 981 | /* Check there is enough space in the buffer provided by the |
| 982 | * user. */ |
| 983 | if( xNextMessageLength > xBufferLengthBytes ) |
| 984 | { |
| 985 | /* The user has provided insufficient space to read the message |
| 986 | * so return the buffer to its previous state (so the length of |
| 987 | * the message is in the buffer again). */ |
| 988 | pxStreamBuffer->xTail = xOriginalTail; |
| 989 | xNextMessageLength = 0; |
| 990 | } |
| 991 | else |
| 992 | { |
| 993 | mtCOVERAGE_TEST_MARKER(); |
| 994 | } |
| 995 | } |
| 996 | else |
| 997 | { |
| 998 | /* A stream of bytes is being received (as opposed to a discrete |
| 999 | * message), so read as many bytes as possible. */ |
| 1000 | xNextMessageLength = xBufferLengthBytes; |
| 1001 | } |
| 1002 | |
| 1003 | /* Read the actual data. */ |
| 1004 | xReceivedLength = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xNextMessageLength, xBytesAvailable ); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */ |
| 1005 | |
| 1006 | return xReceivedLength; |
| 1007 | } |
| 1008 | /*-----------------------------------------------------------*/ |
| 1009 | |
| 1010 | BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) |
no test coverage detected