summaryrefslogtreecommitdiffstats
path: root/src/ByteBuffer.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-03-05 14:03:55 +0100
committerGitHub <noreply@github.com>2021-03-05 14:03:55 +0100
commit868cd94ee9a5a0638c014a4cc42224f01ff234c8 (patch)
treecd23dc866f77de5b0b3e89a5eafeeb2ef24ffbdd /src/ByteBuffer.cpp
parentfixed the crash on generating in the SinglePiceStructuresGen (#5136) (diff)
downloadcuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.gz
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.bz2
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.lz
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.xz
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.zst
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.zip
Diffstat (limited to 'src/ByteBuffer.cpp')
-rw-r--r--src/ByteBuffer.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 3891af247..127227180 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -856,6 +856,34 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count)
+bool cByteBuffer::WriteBuf(size_t a_Count, unsigned char a_Value)
+{
+ CHECK_THREAD
+ CheckValid();
+ PUTBYTES(a_Count);
+ ASSERT(m_BufferSize >= m_ReadPos);
+ size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos;
+ if (BytesToEndOfBuffer <= a_Count)
+ {
+ // Reading across the ringbuffer end, read the first part and adjust parameters:
+ memset(m_Buffer + m_WritePos, a_Value, BytesToEndOfBuffer);
+ a_Count -= BytesToEndOfBuffer;
+ m_WritePos = 0;
+ }
+
+ // Read the rest of the bytes in a single read (guaranteed to fit):
+ if (a_Count > 0)
+ {
+ memset(m_Buffer + m_WritePos, a_Value, a_Count);
+ m_WritePos += a_Count;
+ }
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::ReadSome(ContiguousByteBuffer & a_String, size_t a_Count)
{
CHECK_THREAD