cByteBuffer uses void * instead of char * in data interface.
This makes it compatible with any pointer type.
This commit is contained in:
parent
a02e8e8021
commit
616fb15508
@ -171,7 +171,7 @@ cByteBuffer::~cByteBuffer()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
|
bool cByteBuffer::Write(const void * a_Bytes, size_t a_Count)
|
||||||
{
|
{
|
||||||
CHECK_THREAD;
|
CHECK_THREAD;
|
||||||
CheckValid();
|
CheckValid();
|
||||||
@ -187,13 +187,14 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
|
|||||||
}
|
}
|
||||||
ASSERT(m_BufferSize >= m_WritePos);
|
ASSERT(m_BufferSize >= m_WritePos);
|
||||||
size_t TillEnd = m_BufferSize - m_WritePos;
|
size_t TillEnd = m_BufferSize - m_WritePos;
|
||||||
|
const char * Bytes = (const char *)a_Bytes;
|
||||||
if (TillEnd <= a_Count)
|
if (TillEnd <= a_Count)
|
||||||
{
|
{
|
||||||
// Need to wrap around the ringbuffer end
|
// Need to wrap around the ringbuffer end
|
||||||
if (TillEnd > 0)
|
if (TillEnd > 0)
|
||||||
{
|
{
|
||||||
memcpy(m_Buffer + m_WritePos, a_Bytes, TillEnd);
|
memcpy(m_Buffer + m_WritePos, Bytes, TillEnd);
|
||||||
a_Bytes += TillEnd;
|
Bytes += TillEnd;
|
||||||
a_Count -= TillEnd;
|
a_Count -= TillEnd;
|
||||||
WrittenBytes = TillEnd;
|
WrittenBytes = TillEnd;
|
||||||
}
|
}
|
||||||
@ -203,7 +204,7 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
|
|||||||
// We're guaranteed that we'll fit in a single write op
|
// We're guaranteed that we'll fit in a single write op
|
||||||
if (a_Count > 0)
|
if (a_Count > 0)
|
||||||
{
|
{
|
||||||
memcpy(m_Buffer + m_WritePos, a_Bytes, a_Count);
|
memcpy(m_Buffer + m_WritePos, Bytes, a_Count);
|
||||||
m_WritePos += a_Count;
|
m_WritePos += a_Count;
|
||||||
WrittenBytes += a_Count;
|
WrittenBytes += a_Count;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
~cByteBuffer();
|
~cByteBuffer();
|
||||||
|
|
||||||
/// Writes the bytes specified to the ringbuffer. Returns true if successful, false if not
|
/// Writes the bytes specified to the ringbuffer. Returns true if successful, false if not
|
||||||
bool Write(const char * a_Bytes, size_t a_Count);
|
bool Write(const void * a_Bytes, size_t a_Count);
|
||||||
|
|
||||||
/// Returns the number of bytes that can be successfully written to the ringbuffer
|
/// Returns the number of bytes that can be successfully written to the ringbuffer
|
||||||
size_t GetFreeSpace(void) const;
|
size_t GetFreeSpace(void) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user