JsonConsumer#

Fully qualified name: omni::structuredlog::JsonConsumer

Defined in omni/structuredlog/JsonSerializer.h

class JsonConsumer#

An interface for consuming the output JSON from the JsonSerializer.

Subclassed by omni::structuredlog::JsonLengthCounter, omni::structuredlog::JsonPrinter, omni::structuredlog::JsonStreamer< OutputIt >

Public Functions

inline virtual ~JsonConsumer()#
virtual void consume(
const char *json,
size_t jsonLen,
JsonToken token,
) noexcept = 0#

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.

virtual void consumeRaw(JsonRawValue value) noexcept = 0#

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.

virtual void terminate() noexcept = 0#

Terminate the output, if needed.

Remark

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

virtual bool canConsumeRaw() noexcept = 0#

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.