| 723 | |
| 724 | |
| 725 | bool cByteBuffer::ReadString(AString & a_String, size_t a_Count) |
| 726 | { |
| 727 | CHECK_THREAD; |
| 728 | CheckValid(); |
| 729 | NEEDBYTES(a_Count); |
| 730 | a_String.clear(); |
| 731 | a_String.reserve(a_Count); |
| 732 | ASSERT(m_BufferSize >= m_ReadPos); |
| 733 | size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos; |
| 734 | if (BytesToEndOfBuffer <= a_Count) |
| 735 | { |
| 736 | // Reading across the ringbuffer end, read the first part and adjust parameters: |
| 737 | if (BytesToEndOfBuffer > 0) |
| 738 | { |
| 739 | a_String.assign(m_Buffer + m_ReadPos, BytesToEndOfBuffer); |
| 740 | ASSERT(a_Count >= BytesToEndOfBuffer); |
| 741 | a_Count -= BytesToEndOfBuffer; |
| 742 | } |
| 743 | m_ReadPos = 0; |
| 744 | } |
| 745 | |
| 746 | // Read the rest of the bytes in a single read (guaranteed to fit): |
| 747 | if (a_Count > 0) |
| 748 | { |
| 749 | a_String.append(m_Buffer + m_ReadPos, a_Count); |
| 750 | m_ReadPos += a_Count; |
| 751 | } |
| 752 | return true; |
| 753 | } |
| 754 | |
| 755 | |
| 756 |
no test coverage detected