MCPcopy Create free account
hub / github.com/cuberite/cuberite / ReadBuf

Method ReadBuf

src/ByteBuffer.cpp:662–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

660
661
662bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
663{
664 CHECK_THREAD;
665 CheckValid();
666 NEEDBYTES(a_Count);
667 char * Dst = (char *)a_Buffer; // So that we can do byte math
668 ASSERT(m_BufferSize >= m_ReadPos);
669 size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
670 if (BytesToEndOfBuffer <= a_Count)
671 {
672 // Reading across the ringbuffer end, read the first part and adjust parameters:
673 if (BytesToEndOfBuffer > 0)
674 {
675 memcpy(Dst, m_Buffer + m_ReadPos, BytesToEndOfBuffer);
676 Dst += BytesToEndOfBuffer;
677 a_Count -= BytesToEndOfBuffer;
678 }
679 m_ReadPos = 0;
680 }
681
682 // Read the rest of the bytes in a single read (guaranteed to fit):
683 if (a_Count > 0)
684 {
685 memcpy(Dst, m_Buffer + m_ReadPos, a_Count);
686 m_ReadPos += a_Count;
687 }
688 return true;
689}
690
691
692

Callers 2

ParseItemMethod · 0.80
ParseSlotMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected