| 614 | } |
| 615 | |
| 616 | bool AsioProtobufOutStream::Next(void** data, int* size) |
| 617 | { |
| 618 | if (m_Buffered == l_BufferSize) { |
| 619 | Flush(); |
| 620 | } |
| 621 | // Prepare a new buffer segment that the Protobuf serializer can write into. |
| 622 | // The buffer size is fixed to l_BufferSize, and as seen above, we flush if the previous buffer |
| 623 | // segment was fully used (which is always the case on each Next call after the initial one), so |
| 624 | // we'll end up reusing the same memory region for each Next call because when we flush, we also |
| 625 | // consume the committed data, and that region becomes writable again. |
| 626 | auto buf = m_Writer.Prepare(l_BufferSize - m_Buffered); |
| 627 | *data = buf.data(); |
| 628 | *size = static_cast<int>(l_BufferSize); |
| 629 | m_Buffered = l_BufferSize; |
| 630 | return true; |
| 631 | } |
| 632 | |
| 633 | void AsioProtobufOutStream::BackUp(int count) |
| 634 | { |