|
E-MailRelay
|
A class that does line buffering, supporting auto-detection of line endings and fixed-size extraction. More...
#include <glinebuffer.h>
Public Member Functions | |
| LineBuffer (LineBufferConfig) | |
| Constructor. | |
| void | add (const std::string &data) |
| Adds a data segment. | |
| void | add (const char *data, size_t size) |
| Adds a data segment. | |
| void | expect (size_t n) |
| The next 'n' bytes extracted will be extracted in one contiguous block, without regard to line endings. More... | |
| std::string | eol () const |
| Returns the end-of-line string as passed in to the constructor, or as auto-detected. More... | |
| template<typename Tsink > | |
| void | apply (const char *data, size_t data_size, Tsink sink) |
| Adds the data and passes complete lines to the sink functor with line-data, line-size and eol-size parameters. More... | |
| bool | more () |
| Returns true if there is lineData() to be had. | |
| const char * | lineData () const |
| Returns a pointer for the current line, including the line ending. More... | |
| size_t | lineSize () const |
| Returns the size of the current line, excluding the line ending. More... | |
| size_t | eolSize () const |
| Returns the size of current line ending. More... | |
| template<typename T > | |
| void | apply (const char *data, size_t size, T sink) |
A class that does line buffering, supporting auto-detection of line endings and fixed-size extraction.
Raw data is added, and newline-delimited lines are extracted, optionally via an iterator.
Usage:
Definition at line 53 of file glinebuffer.h.
| void GNet::LineBuffer::apply | ( | const char * | data, |
| size_t | data_size, | ||
| Tsink | sink | ||
| ) |
Adds the data and passes complete lines to the sink functor with line-data, line-size and eol-size parameters.
Stops if the sink functor returns false. This method is zero-copy if the supplied data contains several complete lines.
| std::string GNet::LineBuffer::eol | ( | ) | const |
Returns the end-of-line string as passed in to the constructor, or as auto-detected.
Returns the empty string if auto-detection by iteration has not yet occurred.
Definition at line 262 of file glinebuffer.cpp.
| size_t GNet::LineBuffer::eolSize | ( | ) | const |
Returns the size of current line ending.
This will be zero if extracting a fixed-size block. (It will never be zero as a result of auto-detection because auto-detection has already happened.) Precondition: more()
Definition at line 276 of file glinebuffer.cpp.
| void GNet::LineBuffer::expect | ( | size_t | n | ) |
The next 'n' bytes extracted will be extracted in one contiguous block, without regard to line endings.
This method can be used during a data-transfer phase to obtain a chunk of data of known size, as in http with a specific content-length.
Definition at line 257 of file glinebuffer.cpp.
| const char * GNet::LineBuffer::lineData | ( | ) | const |
Returns a pointer for the current line, including the line ending.
Precondition: more()
Definition at line 286 of file glinebuffer.cpp.
| size_t GNet::LineBuffer::lineSize | ( | ) | const |
Returns the size of the current line, excluding the line ending.
Precondition: more()
Definition at line 281 of file glinebuffer.cpp.
1.8.9.1