Encoders/decoders: TSKV, hex, and related parsers.
Classes | |
| class | TskvParser |
| A streaming parser for the TSKV variant that userver emits. More... | |
Enumerations | |
| enum class | EncodeTskvMode { kKey , kValue , kKeyReplacePeriod } |
Functions | |
| char | ToHexChar (int num) |
| Converts number to hex character; number must be within range [0,16) | |
| constexpr size_t | FromHexUpperBound (size_t size) noexcept |
| Return upper limit on number of characters required to unhex input of given size. | |
| void | ToHex (std::string_view input, std::string &out) noexcept |
Converts input to hex and writes data to output out. | |
| void | ToHexBuffer (std::string_view input, utils::span< char > out) noexcept |
Converts input to hex and writes data to output out. | |
| std::string | ToHex (std::string_view data) noexcept |
| Allocates std::string, converts input and writes into said string. | |
| std::string | ToHex (const void *encoded, size_t len) noexcept |
| Allocates std::string, converts input and writes into said string. | |
| size_t | FromHex (std::string_view encoded, std::string &out) noexcept |
Converts as much of input from hex as possible and writes data into out. | |
| std::string | FromHex (std::string_view encoded) noexcept |
| This FromHex overload allocates string and calls FromHex; if data is not fully a hex string, then it will be only partially processed. | |
| std::string_view | GetHexPart (std::string_view encoded) noexcept |
| bool | IsHexData (std::string_view encoded) noexcept |
| Checks that given range is fully a hex string. That is, if passed to FromHex, it will be fully processed. | |
| std::string | ToHexString (uint64_t value) |
| Interprets uint64_t value as array of bytes and applies ToHex to it. | |
| template<typename OutIter> | |
| OutIter | EncodeTskv (OutIter destination, char ch, EncodeTskvMode mode) |
| Encode according to the TSKV rules, but without escaping the quotation mark ("). | |
| template<typename Container> | |
| void | EncodeTskv (Container &container, std::string_view str, EncodeTskvMode mode) |
| Encode according to the TSKV rules, but without escaping the quotation mark ("). | |
| template<typename OutIter> | |
| USERVER_IMPL_FORCE_INLINE OutIter | EncodeTskv (OutIter destination, char ch, EncodeTskvMode mode) |
| Encode according to the TSKV rules, but without escaping the quotation mark ("). | |
| template<typename TagConsumer> | |
| TskvParser::RecordStatus | TskvReadRecord (TskvParser &parser, TagConsumer consumer) |
| Read all keys-values for 1 TSKV record. | |
| constexpr size_t | LengthInHexForm (size_t size) noexcept |
| Calculate expected length of input after being hex encoded. | |
| constexpr size_t | LengthInHexForm (std::string_view data) noexcept |
Variables | |
| constexpr char | kTskvKeyValueSeparator = '=' |
| constexpr char | kTskvPairsSeparator = '\t' |
| void utils::encoding::EncodeTskv | ( | Container & | container, |
| std::string_view | str, | ||
| EncodeTskvMode | mode ) |
Encode according to the TSKV rules, but without escaping the quotation mark (").
container. Some extra memory is reserved as necessary. | Container | must be continuous and support at least the following operations: 1) c.data() 2) c.size() 3) c.resize(new_size) |
| OutIter utils::encoding::EncodeTskv | ( | OutIter | destination, |
| char | ch, | ||
| EncodeTskvMode | mode ) |
| USERVER_IMPL_FORCE_INLINE OutIter utils::encoding::EncodeTskv | ( | OutIter | destination, |
| char | ch, | ||
| EncodeTskvMode | mode ) |
|
inlinenoexcept |
|
noexcept |
Converts as much of input from hex as possible and writes data into out.
To convert some range from hex, range must have even number of elements and every element must be hex character. To avoid throwing, algorithms consumes as much data as possible and returns how much it was able to process
| encoded | input range to convert |
| out | Result will be written into out. Previous value will be cleared. |
|
constexprnoexcept |
Return upper limit on number of characters required to unhex input of given size.
For example:
|
noexcept |
Returns range that constitutes hex string - e.g. sub-view of encoded that could be fully interpreted as hex string. Basically, if you have string_view a and c = GetHexPart(a), then range FromHex(c) will be fully parsed.
| encoded | input array of bytes. |
|
constexprnoexcept |
|
constexprnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
Converts input to hex and writes data to output out.
| input | bytes to convert |
| out | string to write data. out will be cleared |
|
noexcept |
Converts input to hex and writes data to output out.
out must be pre-allocated to at least utils::encoding::LengthInHexForm bytes. | input | bytes to convert |
| out | buffer to write data |
| char utils::encoding::ToHexChar | ( | int | num | ) |
Converts number to hex character; number must be within range [0,16)
| out_of_bounds | exception if num is out of range |
|
inline |
| TskvParser::RecordStatus utils::encoding::TskvReadRecord | ( | TskvParser & | parser, |
| TagConsumer | consumer ) |
Read all keys-values for 1 TSKV record.
| parser | parser that should have already found the start of the TSKV record using TskvParser::SkipToRecordBegin |
| consumer | a lambda with the signature (const std::string&, const std::string&) -> bool; the strings are temporaries, references to them should not be stored; can return false to skip the record and return immediately |
Usage example:
Definition at line 38 of file tskv_parser_read.hpp.
|
inlineconstexpr |