From 58c051f564f1ab0fefde71b56c899414463a84ba Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 1 Sep 2014 21:36:09 +0200 Subject: [PATCH] Added comments --- JsonGenerator/IndentedPrint.h | 8 ++++++++ JsonGenerator/JsonPrettyPrint.h | 1 + JsonGenerator/JsonPrintable.h | 13 ++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/JsonGenerator/IndentedPrint.h b/JsonGenerator/IndentedPrint.h index c1aedb0a7..ace141444 100644 --- a/JsonGenerator/IndentedPrint.h +++ b/JsonGenerator/IndentedPrint.h @@ -11,6 +11,9 @@ namespace ArduinoJson { namespace Generator { + // Decorator on top of Print to allow indented output. + // This class is used by JsonPrintable::prettyPrintTo() but can also be used + // for your own purpose, like logging. class IndentedPrint : public Print { public: @@ -25,8 +28,13 @@ namespace ArduinoJson virtual size_t write(uint8_t); + // Adds one level of indentation void indent(); + + // Removes one level of indentation void unindent(); + + // Set the number of space printed for each level of indentation void setTabSize(uint8_t n); private: diff --git a/JsonGenerator/JsonPrettyPrint.h b/JsonGenerator/JsonPrettyPrint.h index 4c98c489d..decff82d0 100644 --- a/JsonGenerator/JsonPrettyPrint.h +++ b/JsonGenerator/JsonPrettyPrint.h @@ -12,6 +12,7 @@ namespace ArduinoJson { namespace Generator { + // Converts a compact JSON string into an indented one. class JsonPrettyPrint : public Print { public: diff --git a/JsonGenerator/JsonPrintable.h b/JsonGenerator/JsonPrintable.h index ee225e547..3eec80e22 100644 --- a/JsonGenerator/JsonPrintable.h +++ b/JsonGenerator/JsonPrintable.h @@ -13,16 +13,27 @@ namespace ArduinoJson { namespace Generator { + // Contains methods to generate a JSON string. + // Implemented by both JsonObject and JsonArray class JsonPrintable : public Printable { public: + // Generates the compact JSON string and sends it to a Print stream virtual size_t printTo(Print& p) const = 0; + // Generates the compact JSON string and writes it in a buffer size_t printTo(char* buffer, size_t bufferSize) const; - size_t prettyPrintTo(IndentedPrint& p) const; + // Generates the indented JSON string and sends it to a Print stream size_t prettyPrintTo(Print& p) const; + + // Generates the indented JSON string and sends it to a IndentedPrint stream + // This overload allows a finer control of the output because you can customize + // the IndentedPrint. + size_t prettyPrintTo(IndentedPrint& p) const; + + // Generates the indented JSON string and writes it in a buffer size_t prettyPrintTo(char* buffer, size_t bufferSize) const; }; }