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*,
size_t jsonLen,
JsonToken token,
) noexcept override#

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 that jsonLen may be used to refer to a substring of json.

  • token[in] The type of JSON token being consumed.

inline virtual void consumeRaw(JsonRawValue value) noexcept override#

The function that will consume raw non-string JSON values.

Remark

This will be called if the class returns true from canConsumeRaw().

Parameters:

value[in] The raw value being consumed.

inline virtual void terminate() noexcept override#

Terminate the output, if needed.

Remark

This will be called to ensure the output is null terminated.

inline virtual bool canConsumeRaw() noexcept override#

Determines whether the consumer wants to consume raw values.

Note

If this returns true, string values will no longer be escaped.

Note

Regardless of the return value of this, consume() will still be called and may still be called when JsonToken is eValue.

Returns:

true if the consumer wants to consume raw values, false otherwise.

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.