1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-24 04:01:07 +03:00

Make a ChainedByteRange (build fixes included)

Reviewed By: mjoras

Differential Revision: D59473502

fbshipit-source-id: 30bb72fb5e07d12d9574a39fbeb9b8d3e76b36e6
This commit is contained in:
Aman Sharma
2024-07-09 10:52:57 -07:00
committed by Facebook GitHub Bot
parent 916fe09268
commit 987475eb44
9 changed files with 975 additions and 0 deletions

View File

@@ -170,6 +170,14 @@ void BufWriter::insert(const folly::IOBuf* data, size_t limit) {
copy(data, limit);
}
void BufWriter::insert(const ChainedByteRangeHead* data) {
insert(data, data->chainLength());
}
void BufWriter::insert(const ChainedByteRangeHead* data, size_t limit) {
copy(&data->head, limit);
}
void BufWriter::append(size_t len) {
iobuf_.append(len);
written_ += len;
@@ -197,6 +205,27 @@ void BufWriter::copy(const folly::IOBuf* data, size_t limit) {
CHECK_GE(limit, totalInserted);
}
void BufWriter::copy(const ChainedByteRange* data, size_t limit) {
if (!limit) {
return;
}
sizeCheck(limit);
size_t totalInserted = 0;
const ChainedByteRange* curBuf = data;
auto remaining = limit;
do {
auto lenToCopy = std::min(curBuf->length(), remaining);
push(curBuf->getRange().begin(), lenToCopy);
totalInserted += lenToCopy;
remaining -= lenToCopy;
if (lenToCopy < curBuf->length()) {
break;
}
curBuf = curBuf->getNext();
} while (remaining && curBuf != data);
CHECK_GE(limit, totalInserted);
}
void BufWriter::backFill(const uint8_t* data, size_t len, size_t destOffset) {
CHECK_GE(appendCount_, len);
appendCount_ -= len;