* Get the current Cursor position relative to the head of IOBuf chain.
*/
size_t getCurrentPosition() const {
+ dcheckIntegrity();
return (crtPos_ - crtBegin_) + absolutePos_;
}
const uint8_t* data() const {
+ dcheckIntegrity();
return crtPos_;
}
* pointing at the end of a buffer.
*/
size_t length() const {
+ dcheckIntegrity();
return crtEnd_ - crtPos_;
}
* Return true if the cursor is at the end of the entire IOBuf chain.
*/
bool isAtEnd() const {
+ dcheckIntegrity();
// Check for the simple cases first.
if (crtPos_ != crtEnd_) {
return false;
void skipWhile(const Predicate& predicate);
size_t skipAtMost(size_t len) {
+ dcheckIntegrity();
if (LIKELY(crtPos_ + len < crtEnd_)) {
crtPos_ += len;
return len;
}
void skip(size_t len) {
+ dcheckIntegrity();
if (LIKELY(crtPos_ + len < crtEnd_)) {
crtPos_ += len;
} else {
}
size_t retreatAtMost(size_t len) {
+ dcheckIntegrity();
if (len <= static_cast<size_t>(crtPos_ - crtBegin_)) {
crtPos_ -= len;
return len;
}
void retreat(size_t len) {
+ dcheckIntegrity();
if (len <= static_cast<size_t>(crtPos_ - crtBegin_)) {
crtPos_ -= len;
} else {
}
size_t pullAtMost(void* buf, size_t len) {
+ dcheckIntegrity();
// Fast path: it all fits in one buffer.
if (LIKELY(crtPos_ + len <= crtEnd_)) {
memcpy(buf, data(), len);
}
void pull(void* buf, size_t len) {
+ dcheckIntegrity();
if (LIKELY(crtPos_ + len <= crtEnd_)) {
memcpy(buf, data(), len);
crtPos_ += len;
}
protected:
+ void dcheckIntegrity() const {
+ DCHECK(crtBegin_ <= crtPos_ && crtPos_ <= crtEnd_);
+ DCHECK(crtBuf_ == nullptr || crtBegin_ == crtBuf_->data());
+ DCHECK(
+ crtBuf_ == nullptr ||
+ (uint64_t)(crtEnd_ - crtBegin_) == crtBuf_->length());
+ }
+
~CursorBase() { }
BufType* head() {
}
void advanceBufferIfEmpty() {
+ dcheckIntegrity();
if (crtPos_ == crtEnd_) {
tryAdvanceBuffer();
}
this->crtPos_ = this->crtBegin_ + offset;
}
void gatherAtMost(size_t n) {
+ this->dcheckIntegrity();
size_t size = std::min(n, this->totalLength());
size_t offset = this->crtPos_ - this->crtBegin_;
this->crtBuf_->gather(offset + size);
}
void insert(std::unique_ptr<folly::IOBuf> buf) {
+ this->dcheckIntegrity();
this->absolutePos_ += buf->computeChainDataLength();
if (this->crtPos_ == this->crtBegin_ && this->crtBuf_ != this->buffer_) {
// Can just prepend
}
uint8_t* writableData() {
+ this->dcheckIntegrity();
return this->crtBuf_->writableData() + (this->crtPos_ - this->crtBegin_);
}