mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 08:48:30 +01:00
69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "JsonWriter.hpp"
|
|
#include "IndentedPrint.hpp"
|
|
|
|
namespace ArduinoJson
|
|
{
|
|
namespace Internals
|
|
{
|
|
class PrettyJsonWriter : public JsonWriter
|
|
{
|
|
public:
|
|
explicit PrettyJsonWriter(IndentedPrint* sink)
|
|
: JsonWriter(sink), _indenter(sink)
|
|
{
|
|
}
|
|
|
|
virtual void beginArray()
|
|
{
|
|
_length += _sink->write('[');
|
|
indent();
|
|
}
|
|
|
|
virtual void endArray()
|
|
{
|
|
unindent();
|
|
_length += _sink->write(']');
|
|
}
|
|
|
|
virtual void writeColon()
|
|
{
|
|
_length += _sink->print(": ");
|
|
}
|
|
|
|
virtual void writeComma()
|
|
{
|
|
_length += _sink->write(',');
|
|
_length += _indenter->println();
|
|
}
|
|
|
|
virtual void beginObject()
|
|
{
|
|
_length += _sink->write('{');
|
|
indent();
|
|
}
|
|
|
|
virtual void endObject()
|
|
{
|
|
unindent();
|
|
_length += _sink->write('}');
|
|
}
|
|
|
|
private:
|
|
IndentedPrint* _indenter;
|
|
|
|
void indent()
|
|
{
|
|
_indenter->indent();
|
|
_length += _indenter->println();
|
|
}
|
|
|
|
void unindent()
|
|
{
|
|
_length += _indenter->println();
|
|
_indenter->unindent();
|
|
}
|
|
};
|
|
}
|
|
} |