diff options
Diffstat (limited to 'src/mongo/util/bufreader.h')
| -rw-r--r-- | src/mongo/util/bufreader.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/util/bufreader.h b/src/mongo/util/bufreader.h index 8c30070bada..b8d931add9a 100644 --- a/src/mongo/util/bufreader.h +++ b/src/mongo/util/bufreader.h @@ -106,6 +106,11 @@ public: invariant(_pos >= _start); } + /** back up to beginging of buffer */ + void rewindToStart() { + _pos = _start; + } + /** return current position pointer, and advance by len */ const void* skip(unsigned len) { ConstDataRangeCursor cdrc(_pos, _end); @@ -124,6 +129,14 @@ public: s = readCStr().toString(); } + /** + * Return a view of the next len bytes and advance by len. + */ + StringData readBytes(size_t len) { + // Note: the call to skip() includes a check that at least 'len' bytes remain in the buffer. + return StringData(reinterpret_cast<const char*>(skip(len)), len); + } + const void* pos() { return _pos; } |
