Skip to content

Commit

Permalink
Use buffer.data() to circumvent MSVC implementation of std::array
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt committed Jan 26, 2023
1 parent e86cb37 commit bca2180
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/networkmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand All @@ -40,7 +40,7 @@ void NetworkMessage::addString(const std::string& value)
}

add<uint16_t>(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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/networkmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/outputmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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;
}

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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit bca2180

Please sign in to comment.