| 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 |