| 146 | } |
| 147 | |
| 148 | Status Chunker::ProcessFinal(std::shared_ptr<Buffer> partial, |
| 149 | std::shared_ptr<Buffer> block, |
| 150 | std::shared_ptr<Buffer>* completion, |
| 151 | std::shared_ptr<Buffer>* rest) { |
| 152 | if (partial->size() == 0) { |
| 153 | // If partial is empty, don't bother looking for completion |
| 154 | *completion = SliceBuffer(block, 0, 0); |
| 155 | *rest = block; |
| 156 | return Status::OK(); |
| 157 | } |
| 158 | int64_t first_pos = -1; |
| 159 | RETURN_NOT_OK(boundary_finder_->FindFirst(std::string_view(*partial), |
| 160 | std::string_view(*block), &first_pos)); |
| 161 | if (first_pos == BoundaryFinder::kNoDelimiterFound) { |
| 162 | // No delimiter in block => it's entirely a completion of partial |
| 163 | *completion = block; |
| 164 | *rest = SliceBuffer(std::move(block), 0, 0); |
| 165 | } else { |
| 166 | *completion = SliceBuffer(block, 0, first_pos); |
| 167 | *rest = SliceBuffer(std::move(block), first_pos); |
| 168 | } |
| 169 | return Status::OK(); |
| 170 | } |
| 171 | |
| 172 | Status Chunker::ProcessSkip(std::shared_ptr<Buffer> partial, |
| 173 | std::shared_ptr<Buffer> block, bool final, int64_t* count, |