#include <userver/utils/encoding/tskv_parser.hpp>
A streaming parser for the TSKV variant that userver emits.
Supported syntax
\n
character\t
charactertskv
=
Escaping
\n
, \t
, \\
in keys or values SHOULD be escaped as "\\\n"
, "\\\t"
, "\\\\"</tt>
2. <tt>=</tt> SHOULD be escaped as <tt>"\="</tt> in keys, MAY be escaped in values
3. <tt>\\r</tt> and <tt>\\0</tt> MAY be escaped as <tt>"\\r"</tt>, <tt>"\\0"
Parsing process Initialize TskvParser
with a caller-owned string that may contain a single or multiple TSKV records. For each record, first call SkipToRecordBegin
. Then call ReadKey
and ReadValue
a bunch of times.
For a simpler way to read TSKV records, see utils::encoding::TskvReadRecord.
Definition at line 35 of file tskv_parser.hpp.
Public Types | |
enum class | RecordStatus { kReachedEnd , kIncomplete } |
Public Member Functions | |
TskvParser (std::string_view in) noexcept | |
const char * | SkipToRecordBegin () noexcept |
Skips the current record or optional invalid junk until it finds the start of the a valid record. | |
RecordStatus | SkipToRecordEnd () noexcept |
Skips to the end of the current record, which might not be the same as the start of the next valid record. | |
std::optional< RecordStatus > | ReadKey (std::string &result) |
Parses the key, replacing result with it. | |
std::optional< RecordStatus > | ReadValue (std::string &result) |
Parses the value, replacing result with it. | |
const char * | GetStreamPosition () const noexcept |
|
strong |
The status is returned once the record is complete. We ignore invalid escaping, not reporting it as an error, trying to push through. nullopt
status means we should keep reading the current TSKV record.
Enumerator | |
---|---|
kReachedEnd | successfully read the whole record |
kIncomplete | the record ends abruptly, the service is probably still writing the record |
Definition at line 40 of file tskv_parser.hpp.
std::optional< RecordStatus > utils::encoding::TskvParser::ReadKey | ( | std::string & | result | ) |
Parses the key, replacing result
with it.
std::bad_alloc | only if std::string allocation throws |
\t\n
sequence std::optional< RecordStatus > utils::encoding::TskvParser::ReadValue | ( | std::string & | result | ) |
Parses the value, replacing result
with it.
std::bad_alloc | only if std::string allocation throws |
Skips the current record or optional invalid junk until it finds the start of the a valid record.
nullptr
otherwise tskv\n
records are currently not supported
|
noexcept |
Skips to the end of the current record, which might not be the same as the start of the next valid record.
tskv\n
records are currently not supported