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) noexcept override

The function that will consume strings of JSON.


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.

  • 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.

inline virtual void terminate() noexcept override

Terminate the output, if needed.


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.


the number of bytes that have been consumed so far.