#include <userver/utils/encoding/tskv_parser.hpp>
A streaming parser for the TSKV variant that userver emits.
Supported syntax
Escaping
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 36 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. | |
| std::optional< RecordStatus > | ReadValueView (std::string_view &result, std::string &storage) |
| Parses a value without copying it when it contains no escapes. | |
| std::optional< RecordStatus > | SkipValue () noexcept |
| Skips one value with the same escape and EOF handling as utils::encoding::TskvParser::ReadValue, without materializing it. | |
| const char * | GetStreamPosition () const noexcept |
|
nodiscardstrong |
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 41 of file tskv_parser.hpp.
|
noexcept |
| 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 |
| 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 |
| std::optional< RecordStatus > utils::encoding::TskvParser::ReadValueView | ( | std::string_view & | result, |
| std::string & | storage ) |
Parses a value without copying it when it contains no escapes.
| result | view of the parsed value; empty on an incomplete value |
| storage | scratch buffer used only when decoding escapes |
| std::bad_alloc | only if scratch buffer allocation throws |
|
noexcept |
Skips the current record or optional invalid junk until it finds the start of the a valid record.
|
noexcept |
Skips to the end of the current record, which might not be the same as the start of the next valid record.
|
noexcept |
Skips one value with the same escape and EOF handling as utils::encoding::TskvParser::ReadValue, without materializing it.