JsonLengthCounter#
Fully qualified name: omni::structuredlog::JsonLengthCounter
Defined in omni/structuredlog/JsonSerializer.h
-
class JsonLengthCounter : public omni::structuredlog::JsonConsumer#
An implementation of JsonConsumer that just counts the length of the output string.
You may serialize some JSON through this to find the required buffer length, then allocate the buffer and serialize the JSON again with JsonPrinter using that allocated buffer.
Public Functions
- inline virtual void consume(
- const char *json,
- size_t jsonLen,
The function that will consume strings of JSON.
Remark
This will be called when the JsonSerializer wants to write something to the output. The JsonSerializer will write very small units of text to this function, so the implementation should plan accordingly.
- Parameters:
json – [in] The string of JSON. This string’s lifetime ends after the return from this call.
jsonLen – [in] The length of
json
, excluding the null terminator. The null terminator will be included in the length when the final call to this writes out a null terminator. It is possible this may be 0 in some edge cases. It’s possible thatjsonLen
may be used to refer to a substring ofjson
.
-
inline virtual void terminate() noexcept override#
Terminate the output, if needed.
Remark
This will be called to ensure the output is null terminated.
-
inline size_t getcount() noexcept#
Get the number of bytes that have been consumed so far.
- Returns:
the number of bytes that have been consumed so far.