Add tryRead() and endian variants
authorNick Terrell <terrelln@fb.com>
Sat, 25 Mar 2017 01:12:06 +0000 (18:12 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sat, 25 Mar 2017 01:23:06 +0000 (18:23 -0700)
commit01944ccd082a967d6a030c5a511a913840f00893
treef7c5b40212eb2fd6a8078e220f441755aa60b9a4
parentc16a3f3775fa166503b4a07150a709c6787c1471
Add tryRead() and endian variants

Summary:
Add a `tryRead()`, and endian variants, which try to read into an arithmetic type, and if there isn't enough data they return false.
One use case is to quickly check if an IOBuf starts with a certain prefix, benchmarks show that using `tryReadLE()` is 6x faster than using `pullAtMost()` and `memcmp()`.

Reviewed By: yfeldblum

Differential Revision: D4767855

fbshipit-source-id: feb8c61092772933d4b8496b27d464559ff8b827
folly/io/Cursor.h
folly/io/test/IOBufCursorBenchmark.cpp
folly/io/test/IOBufCursorTest.cpp