From bca218030fc3960dcd818bf674629d88810ac03f Mon Sep 17 00:00:00 2001 From: Ranieri Althoff Date: Thu, 26 Jan 2023 20:23:29 +0100 Subject: [PATCH] Use buffer.data() to circumvent MSVC implementation of std::array --- src/networkmessage.cpp | 8 ++++---- src/networkmessage.h | 4 ++-- src/outputmessage.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/networkmessage.cpp b/src/networkmessage.cpp index dc0ba8f2e1..d3a83452c8 100644 --- a/src/networkmessage.cpp +++ b/src/networkmessage.cpp @@ -18,7 +18,7 @@ std::string NetworkMessage::getString(uint16_t stringLen /* = 0*/) return std::string(); } - auto it = buffer.begin() + info.position; + auto it = buffer.data() + info.position; info.position += stringLen; return {it, it + stringLen}; } @@ -40,7 +40,7 @@ void NetworkMessage::addString(const std::string& value) } add(stringLen); - std::memcpy(buffer.begin() + info.position, value.data(), stringLen); + std::memcpy(buffer.data() + info.position, value.data(), stringLen); info.position += stringLen; info.length += stringLen; } @@ -58,7 +58,7 @@ void NetworkMessage::addBytes(const char* bytes, size_t size) return; } - std::memcpy(buffer.begin() + info.position, bytes, size); + std::memcpy(buffer.data() + info.position, bytes, size); info.position += size; info.length += size; } @@ -69,7 +69,7 @@ void NetworkMessage::addPaddingBytes(size_t n) return; } - std::fill_n(buffer.begin() + info.position, n, 0x33); + std::fill_n(buffer.data() + info.position, n, 0x33); info.length += n; } diff --git a/src/networkmessage.h b/src/networkmessage.h index 812d30904c..03cdbb3654 100644 --- a/src/networkmessage.h +++ b/src/networkmessage.h @@ -65,7 +65,7 @@ class NetworkMessage } T value; - std::memcpy(&value, buffer.begin() + info.position, sizeof(T)); + std::memcpy(&value, buffer.data() + info.position, sizeof(T)); info.position += sizeof(T); return value; } @@ -94,7 +94,7 @@ class NetworkMessage return; } - std::memcpy(buffer.begin() + info.position, &value, sizeof(T)); + std::memcpy(buffer.data() + info.position, &value, sizeof(T)); info.position += sizeof(T); info.length += sizeof(T); } diff --git a/src/outputmessage.h b/src/outputmessage.h index 4e7eafd39d..3b4461c533 100644 --- a/src/outputmessage.h +++ b/src/outputmessage.h @@ -35,7 +35,7 @@ class OutputMessage : public NetworkMessage void append(const NetworkMessage& msg) { auto msgLen = msg.getLength(); - std::copy_n(msg.getBuffer() + 8, msgLen, buffer.begin() + info.position); + std::memcpy(buffer.data() + info.position, msg.getBuffer() + 8, msgLen); info.length += msgLen; info.position += msgLen; } @@ -43,7 +43,7 @@ class OutputMessage : public NetworkMessage void append(const OutputMessage_ptr& msg) { auto msgLen = msg->getLength(); - std::copy_n(msg->getBuffer() + 8, msgLen, buffer.begin() + info.position); + std::memcpy(buffer.data() + info.position, msg->getBuffer() + 8, msgLen); info.length += msgLen; info.position += msgLen; } @@ -54,7 +54,7 @@ class OutputMessage : public NetworkMessage { assert(outputBufferStart >= sizeof(T)); outputBufferStart -= sizeof(T); - std::copy_n(&add, sizeof(T), buffer.begin() + outputBufferStart); + std::memcpy(buffer.data() + outputBufferStart, &add, sizeof(T)); // added header size to the message size info.length += sizeof(T); }