Add canAdvance to cursor and tests
authorNeel Goyal <ngoyal@fb.com>
Tue, 5 Jan 2016 17:33:55 +0000 (09:33 -0800)
committerfacebook-github-bot-0 <folly-bot@fb.com>
Tue, 5 Jan 2016 18:20:23 +0000 (10:20 -0800)
commit1c77ef4fa650ac53ad9c0ce51b0b73e1f9d1ab87
tree893e4833d3f4e8c8f73dc54c1cfa5c825233d25c
parent3f93d7830a8cf7a3edfe13f87812b2d41825f70b
Add canAdvance to cursor and tests

Summary:
Determine if the cursor can advance N bytes. This is useful if
applications want to check before reading so an exception isn't thrown.
It tries to walk the minimal amount of links needed in the chain.

I had a task that could have used this, though caching totalLength and
macro magic ended up being the implementation chosen. I think this just
adds to the cursor API.

Reviewed By: djwatson

Differential Revision: D2728498

fb-gh-sync-id: 8657653b82a48828cccab143653dc169ef715702
folly/io/Cursor.h
folly/io/test/IOBufCursorTest.cpp