| 50 | } |
| 51 | |
| 52 | std::vector<std::shared_ptr<SerializedPage>> ArbitraryBuffer::getPages( |
| 53 | uint64_t maxBytes) { |
| 54 | BOLT_CHECK_GT(maxBytes, 0, "maxBytes can't be zero"); |
| 55 | |
| 56 | std::vector<std::shared_ptr<SerializedPage>> pages; |
| 57 | uint64_t bytesRemoved{0}; |
| 58 | while (bytesRemoved < maxBytes && !pages_.empty()) { |
| 59 | if (pages_.front() == nullptr) { |
| 60 | // NOTE: keep the end marker in arbitrary buffer to signal all the |
| 61 | // destination buffers after the buffers have all been consumed. |
| 62 | BOLT_CHECK_EQ(pages_.size(), 1); |
| 63 | pages.push_back(nullptr); |
| 64 | break; |
| 65 | } |
| 66 | bytesRemoved += pages_.front()->size(); |
| 67 | pages.push_back(std::move(pages_.front())); |
| 68 | pages_.pop_front(); |
| 69 | } |
| 70 | return pages; |
| 71 | } |
| 72 | |
| 73 | std::string ArbitraryBuffer::toString() const { |
| 74 | return fmt::format( |