proxygen
|
#include <String.h>
Public Member Functions | |
StreamSplitter (char delimiter, Callback &&pieceCb, uint64_t maxLength=0, uint64_t initialCapacity=0) | |
bool | flush () |
bool | operator() (StringPiece in) |
Private Attributes | |
IOBuf | buffer_ |
char | delimiter_ |
uint64_t | maxLength_ |
Callback | pieceCb_ |
Outputs exactly the same bytes as the input stream, in different chunks. A chunk boundary occurs after each delimiter, or, if maxLength is non-zero, after maxLength bytes, whichever comes first. Your callback can return false to stop consuming the stream at any time.
The splitter buffers the last incomplete chunk, so you must call flush() to consume the piece of the stream after the final delimiter. This piece may be empty. After a flush(), the splitter can be re-used for a new stream.
operator() and flush() return false iff your callback returns false. The internal buffer is not flushed, so reusing such a splitter will have indeterminate results. Same goes if your callback throws. Feel free to fix these corner cases if needed.
Tips:
|
inline |
Definition at line 198 of file String.h.
bool folly::gen::StreamSplitter< Callback >::flush | ( | ) |
Consume any incomplete last line (may be empty). Do this before destroying the StreamSplitter, or you will fail to consume part of the input.
After flush() you may proceed to consume the next stream via ().
Returns false if the callback wants no more data, true otherwise. A return value of false means that this splitter must no longer be used.
Definition at line 128 of file String-inl.h.
References buffer_, and folly::gen::detail::ch().
bool folly::gen::StreamSplitter< Callback >::operator() | ( | StringPiece | in | ) |
Consume another piece of the input stream.
Returns false only if your callback refuses to consume more data by returning false (true otherwise). A return value of false means that this splitter must no longer be used.
Definition at line 139 of file String-inl.h.
References folly::Range< Iter >::advance(), folly::Range< Iter >::begin(), buffer_, folly::gen::detail::consumeBufferPlus(), folly::gen::detail::consumeFixedSizeChunks(), folly::Range< Iter >::data(), folly::Range< Iter >::empty(), min, prefix(), folly::Range< Iter >::size(), folly::gen::detail::splitPrefix(), and uint64_t.
|
private |
|
private |
|
private |
|
private |