JsonPrinter#

Fully qualified name: omni::structuredlog::JsonPrinter

Defined in omni/structuredlog/JsonSerializer.h

class JsonPrinter : public omni::structuredlog::JsonConsumer#

An implementation of JsonConsumer that just prints to a fixed string.

Public Functions

inline JsonPrinter()#

Default constructor.

Creates a printer with no output buffer.

inline JsonPrinter(char *output, size_t outputLen) noexcept#

Create a printer from a fixed string buffer.

Parameters:
  • output[out] The instance will write to this buffer.

  • outputLen[in] The number of bytes that can be written to output.

inline void reset(char *output, size_t outputLen) noexcept#

Reinitialize the printer with a new buffer.

Parameters:
  • output[out] The instance will write to this buffer.

  • outputLen[in] The number of bytes that can be written to output.

inline virtual void consume(
const char *json,
size_t jsonLen,
JsonToken token,
) noexcept override#

Write a string into the buffer.

Parameters:
  • json[in] The data to write into the buffer.

  • jsonLen[in] The length of json, excluding any null terminator.

  • token[in] Unused token type.

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 bool hasOverflowed() noexcept#

Check whether more data was printed than would fit in the printer’s buffer.

Returns:

true if the buffer was too small to fit all the consumed data.

Returns:

false if the buffer was able to fit all the consumed data.

inline char *getNextChar() const noexcept#

Get the pointer to the next char to be written in the buffer.

Returns:

The pointer to the next character to be written. If the buffer has overflowed, this will point past the end of the buffer.