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()
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) 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.

inline virtual void terminate() noexcept override

Terminate the output, if needed.

Remark

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

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.