diff options
Diffstat (limited to '')
-rw-r--r-- | src/ByteBuffer.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index f3a6e3a7d..2de6aec60 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -83,7 +83,7 @@ Unfortunately it is very slow, so it is disabled even for regular DEBUG builds. // cByteBuffer: cByteBuffer::cByteBuffer(size_t a_BufferSize) : - m_Buffer(new char[a_BufferSize + 1]), + m_Buffer(new std::byte[a_BufferSize + 1]), m_BufferSize(a_BufferSize + 1), m_DataStart(0), m_WritePos(0), @@ -446,7 +446,15 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value) { LOGWARNING("%s: String too large: %u (%u KiB)", __FUNCTION__, Size, Size / 1024); } - return ReadString(a_Value, static_cast<size_t>(Size)); + ContiguousByteBuffer Buffer; + if (!ReadSome(Buffer, static_cast<size_t>(Size))) + { + return false; + } + // "Convert" a UTF-8 encoded string into system-native char. + // This isn't great, better would be to use codecvt: + a_Value = { reinterpret_cast<const char *>(Buffer.data()), Buffer.size() }; + return true; } @@ -552,6 +560,18 @@ bool cByteBuffer::WriteBEInt8(Int8 a_Value) +bool cByteBuffer::WriteBEInt8(const std::byte a_Value) +{ + CHECK_THREAD + CheckValid(); + PUTBYTES(1); + return WriteBuf(&a_Value, 1); +} + + + + + bool cByteBuffer::WriteBEUInt8(UInt8 a_Value) { CHECK_THREAD @@ -836,7 +856,7 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count) -bool cByteBuffer::ReadString(AString & a_String, size_t a_Count) +bool cByteBuffer::ReadSome(ContiguousByteBuffer & a_String, size_t a_Count) { CHECK_THREAD CheckValid(); @@ -886,11 +906,11 @@ bool cByteBuffer::SkipRead(size_t a_Count) -void cByteBuffer::ReadAll(AString & a_Data) +void cByteBuffer::ReadAll(ContiguousByteBuffer & a_Data) { CHECK_THREAD CheckValid(); - ReadString(a_Data, GetReadableSpace()); + ReadSome(a_Data, GetReadableSpace()); } @@ -944,7 +964,7 @@ void cByteBuffer::ResetRead(void) -void cByteBuffer::ReadAgain(AString & a_Out) +void cByteBuffer::ReadAgain(ContiguousByteBuffer & a_Out) { // Return the data between m_DataStart and m_ReadPos (the data that has been read but not committed) // Used by ProtoProxy to repeat communication twice, once for parsing and the other time for the remote party @@ -1004,8 +1024,3 @@ size_t cByteBuffer::GetVarIntSize(UInt32 a_Value) return Count; } - - - - - |