MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TransferOutWithLimit

Method TransferOutWithLimit

src/network/core/packet.h:105–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 */
104 template <typename F>
105 ssize_t TransferOutWithLimit(F transfer_function, size_t limit)
106 {
107 size_t amount = std::min(this->RemainingBytesToTransfer(), limit);
108 if (amount == 0) return 0;
109
110 assert(this->pos < this->buffer.size());
111 assert(this->pos + amount <= this->buffer.size());
112 auto output_buffer = std::span<const uint8_t>(this->buffer.data() + this->pos, amount);
113 ssize_t bytes = transfer_function(output_buffer);
114 if (bytes > 0) this->pos += bytes;
115 return bytes;
116 }
117
118 /**
119 * Transfer data from the packet to the given function. It starts reading at the

Callers 1

CreatePacketForReadingFunction · 0.80

Calls 3

sizeMethod · 0.45
dataMethod · 0.45

Tested by 1

CreatePacketForReadingFunction · 0.64