MCPcopy Create free account
hub / github.com/apache/brpc / append_to

Method append_to

src/butil/iobuf.cpp:1269–1293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1267}
1268
1269size_t IOBuf::append_to(IOBuf* buf, size_t n, size_t pos) const {
1270 const size_t nref = _ref_num();
1271 // Skip `pos' bytes. `offset' is the starting position in starting BlockRef.
1272 size_t offset = pos;
1273 size_t i = 0;
1274 for (; offset != 0 && i < nref; ++i) {
1275 IOBuf::BlockRef const& r = _ref_at(i);
1276 if (offset < (size_t)r.length) {
1277 break;
1278 }
1279 offset -= r.length;
1280 }
1281 size_t m = n;
1282 for (; m != 0 && i < nref; ++i) {
1283 IOBuf::BlockRef const& r = _ref_at(i);
1284 const size_t nc = std::min(m, (size_t)r.length - offset);
1285 const IOBuf::BlockRef r2 = { (uint32_t)(r.offset + offset),
1286 (uint32_t)nc, r.block };
1287 buf->_push_back_ref(r2);
1288 offset = 0;
1289 m -= nc;
1290 }
1291 // If nref == 0, here returns 0 correctly
1292 return n - m;
1293}
1294
1295size_t IOBuf::copy_to(void* d, size_t n, size_t pos) const {
1296 const size_t nref = _ref_num();

Callers 4

TEST_FFunction · 0.45
CreateMethod · 0.45
ProcessHttpResponseFunction · 0.45
OnBodyMethod · 0.45

Calls 4

_push_back_refMethod · 0.80
lengthFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.36