1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-18 09:52:44 +01:00

Codechange: use std::span for transferring data in network code

This commit is contained in:
Rubidium
2025-04-27 20:08:45 +02:00
committed by rubidium42
parent b7e7f08f78
commit c6ea0ce961
9 changed files with 71 additions and 88 deletions

View File

@@ -52,19 +52,6 @@ struct PacketReader : LoadFilter {
{
}
/**
* Simple wrapper around fwrite to be able to pass it to Packet's TransferOut.
* @param destination The reader to add the data to.
* @param source The buffer to read data from.
* @param amount The number of bytes to copy.
* @return The number of bytes that were copied.
*/
static inline ssize_t TransferOutMemCopy(PacketReader *destination, const char *source, size_t amount)
{
std::copy_n(source, amount, std::back_inserter(destination->buffer));
return amount;
}
/**
* Add a packet to this buffer.
* @param p The packet to add.
@@ -72,7 +59,10 @@ struct PacketReader : LoadFilter {
void AddPacket(Packet &p)
{
assert(this->read_bytes == 0);
p.TransferOut(TransferOutMemCopy, this);
p.TransferOut([this](std::span<const uint8_t> source) {
std::ranges::copy(source, std::back_inserter(this->buffer));
return source.size();
});
}
size_t Read(uint8_t *rbuf, size_t size) override