Splits incoming data into lines using a circular buffer of fixed capacity. More...
#include <sockutils.hpp>
Public Member Functions | |
TLineSplitter (int maxLen) | |
Constructs a line splitter with a fixed ring buffer capacity. | |
TLine | Pop () |
Retrieves and removes the next complete line from the buffer. | |
void | Push (const char *buf, size_t size) |
Appends new data to the circular buffer. | |
Splits incoming data into lines using a circular buffer of fixed capacity.
This class maintains a ring buffer of maximum length (maxLen
), allowing you to push new data in and then pop complete lines without additional copying. When a line wraps around the circular boundary, it is represented in two segments. A corresponding TLine
object holds these segments as string views (Part1
and Part2
).
maxLen
. Pushing more data than the available space may cause old data to be overwritten or an implementation-defined behavior.TLine
references the internal buffer via string views. Any subsequent push operations (or further pops) may invalidate these views.NNet::TLineSplitter::TLineSplitter | ( | int | maxLen | ) |
Constructs a line splitter with a fixed ring buffer capacity.
maxLen | The maximum number of bytes the circular buffer can hold. |
TLine NNet::TLineSplitter::Pop | ( | ) |
Retrieves and removes the next complete line from the buffer.
A line is typically delimited by a newline character (implementation-specific). If the line crosses the circular boundary, TLine
will contain two parts:
Part1
referencing the tail end of the buffer,Part2
referencing the beginning portion.TLine
object with string views that reference the extracted line. If there is no complete line available, behavior may be undefined or implementation-dependent (e.g., returns an empty line or throws).void NNet::TLineSplitter::Push | ( | const char * | buf, |
size_t | size ) |
Appends new data to the circular buffer.
The data is copied into the ring buffer without extra allocations. If the buffer does not have enough free space, the runtime_exception is thrown.
buf | Pointer to the raw bytes to insert. |
size | Number of bytes to insert from buf . |