bool McAsciiParserBase::readValue(folly::IOBuf& buffer, folly::IOBuf& to) { if (remainingIOBufLength_) { // Copy IOBuf for part of (or whole) value. size_t offset = p_ - reinterpret_cast<const char*>(buffer.data()) + 1; size_t toUse = std::min(buffer.length() - offset, remainingIOBufLength_); buffer.cloneOneInto(to); // Adjust buffer pointers. to.trimStart(offset); to.trimEnd(buffer.length() - offset - toUse); remainingIOBufLength_ -= toUse; // Move the state machine to the proper character. p_ += toUse; // Now if we don't have enough data, we need to preallocate second piece // for remaining buffer and signal partial read. if (remainingIOBufLength_) { auto secondPiece = folly::IOBuf::createCombined(remainingIOBufLength_); currentIOBuf_ = secondPiece.get(); to.appendChain(std::move(secondPiece)); return false; } } return true; }
McAsciiParserBase::State McClientAsciiParser::consume(folly::IOBuf& buffer) { assert(state_ == State::PARTIAL && !hasReadBuffer()); p_ = reinterpret_cast<const char*>(buffer.data()); pe_ = p_ + buffer.length(); (this->*consumer_)(buffer); if (savedCs_ == errorCs_) { handleError(buffer); } buffer.trimStart(p_ - reinterpret_cast<const char*>(buffer.data())); return state_; }