| 1350 | } |
| 1351 | |
| 1352 | void const* IOBuf::fetch(void* d, size_t n) const { |
| 1353 | if (n <= length()) { |
| 1354 | IOBuf::BlockRef const& r0 = _ref_at(0); |
| 1355 | if (n <= r0.length) { |
| 1356 | return r0.block->data + r0.offset; |
| 1357 | } |
| 1358 | |
| 1359 | iobuf::cp(d, r0.block->data + r0.offset, r0.length); |
| 1360 | size_t total_nc = r0.length; |
| 1361 | const size_t nref = _ref_num(); |
| 1362 | for (size_t i = 1; i < nref; ++i) { |
| 1363 | IOBuf::BlockRef const& r = _ref_at(i); |
| 1364 | if (n <= r.length + total_nc) { |
| 1365 | iobuf::cp((char*)d + total_nc, |
| 1366 | r.block->data + r.offset, n - total_nc); |
| 1367 | return d; |
| 1368 | } |
| 1369 | iobuf::cp((char*)d + total_nc, r.block->data + r.offset, r.length); |
| 1370 | total_nc += r.length; |
| 1371 | } |
| 1372 | } |
| 1373 | return NULL; |
| 1374 | } |
| 1375 | |
| 1376 | const void* IOBuf::fetch1() const { |
| 1377 | if (!empty()) { |