Serialisation: Add helpers to send/recv length-prefixed binary buffers

This commit is contained in:
Jonathan G Rennison
2023-06-12 22:14:41 +01:00
parent 8c507d6611
commit 79255c0294
2 changed files with 45 additions and 0 deletions

View File

@@ -137,6 +137,22 @@ void BufferSend_binary(std::vector<byte> &buffer, size_t limit, const char *data
buffer.insert(buffer.end(), data, data + size);
}
/**
* Sends a binary buffer over the network.
* The data is length prefixed with a uint16.
* @param data The string to send
*/
void BufferSend_buffer(std::vector<byte> &buffer, size_t limit, const byte *data, const size_t size)
{
assert(size <= UINT16_MAX);
assert(BufferCanWriteToPacket(buffer, limit, size + 2));
buffer.insert(buffer.end(), {
(uint8)GB(size, 0, 8),
(uint8)GB(size, 8, 8),
});
buffer.insert(buffer.end(), data, data + size);
}
void BufferRecvStringValidate(std::string &buffer, StringValidationSettings settings)
{
StrMakeValidInPlace(buffer, settings);