diff --git a/srcs/Internals/CompactJsonWriter.h b/srcs/Internals/CompactJsonWriter.h
index 4af2df15..8fc4f466 100644
--- a/srcs/Internals/CompactJsonWriter.h
+++ b/srcs/Internals/CompactJsonWriter.h
@@ -5,39 +5,39 @@
class CompactJsonWriter : public JsonWriter
{
public:
- explicit CompactJsonWriter(Print& sink)
+ explicit CompactJsonWriter(Print* sink)
: JsonWriter(sink)
{
}
virtual void beginArray()
{
- _length += _sink.write('[');
+ _length += _sink->write('[');
}
virtual void endArray()
{
- _length += _sink.write(']');
+ _length += _sink->write(']');
}
virtual void writeColon()
{
- _length += _sink.write(':');
+ _length += _sink->write(':');
}
virtual void writeComma()
{
- _length += _sink.write(',');
+ _length += _sink->write(',');
}
virtual void beginObject()
{
- _length += _sink.write('{');
+ _length += _sink->write('{');
}
virtual void endObject()
{
- _length += _sink.write('}');
+ _length += _sink->write('}');
}
};
diff --git a/srcs/Internals/EscapedString.cpp b/srcs/Internals/EscapedString.cpp
index 4253d323..0472c9a4 100644
--- a/srcs/Internals/EscapedString.cpp
+++ b/srcs/Internals/EscapedString.cpp
@@ -21,25 +21,25 @@ static inline char getSpecialChar(char c)
return p[1];
}
-static inline size_t printCharTo(char c, Print& p)
+static inline size_t printCharTo(char c, Print* p)
{
char specialChar = getSpecialChar(c);
return specialChar != 0
- ? p.write('\\') + p.write(specialChar)
- : p.write(c);
+ ? p->write('\\') + p->write(specialChar)
+ : p->write(c);
}
-size_t EscapedString::printTo(const char* s, Print& p)
+size_t EscapedString::printTo(const char* s, Print* p)
{
- if (!s) return p.print("null");
+ if (!s) return p->print("null");
- size_t n = p.write('\"');
+ size_t n = p->write('\"');
while (*s)
{
n += printCharTo(*s++, p);
}
- return n + p.write('\"');
+ return n + p->write('\"');
}
\ No newline at end of file
diff --git a/srcs/Internals/EscapedString.h b/srcs/Internals/EscapedString.h
index ab9ec4d9..01a138e7 100644
--- a/srcs/Internals/EscapedString.h
+++ b/srcs/Internals/EscapedString.h
@@ -14,7 +14,7 @@ namespace ArduinoJson
class EscapedString
{
public:
- static size_t printTo(const char*, Print&);
+ static size_t printTo(const char*, Print*);
};
}
}
\ No newline at end of file
diff --git a/srcs/Internals/IndentedPrint.cpp b/srcs/Internals/IndentedPrint.cpp
index 75032831..6a2f3dc2 100644
--- a/srcs/Internals/IndentedPrint.cpp
+++ b/srcs/Internals/IndentedPrint.cpp
@@ -27,7 +27,7 @@ size_t IndentedPrint::write(uint8_t c)
if (isNewLine)
n += writeTabs();
- n += sink.write(c);
+ n += sink->write(c);
isNewLine = c == '\n';
@@ -39,7 +39,7 @@ inline size_t IndentedPrint::writeTabs()
size_t n = 0;
for (int i = 0; i < level*tabSize; i++)
- n += sink.write(' ');
+ n += sink->write(' ');
return n;
}
\ No newline at end of file
diff --git a/srcs/Internals/IndentedPrint.h b/srcs/Internals/IndentedPrint.h
index 2f6f0500..abf65c9d 100644
--- a/srcs/Internals/IndentedPrint.h
+++ b/srcs/Internals/IndentedPrint.h
@@ -19,7 +19,7 @@ namespace ArduinoJson
public:
IndentedPrint(Print& p)
- : sink(p)
+ : sink(&p)
{
level = 0;
tabSize = 2;
@@ -38,7 +38,7 @@ namespace ArduinoJson
void setTabSize(uint8_t n);
private:
- Print& sink;
+ Print* sink;
uint8_t level : 4;
uint8_t tabSize : 3;
bool isNewLine : 1;
diff --git a/srcs/Internals/JsonWriter.cpp b/srcs/Internals/JsonWriter.cpp
index d59f067b..d564d9e7 100644
--- a/srcs/Internals/JsonWriter.cpp
+++ b/srcs/Internals/JsonWriter.cpp
@@ -11,15 +11,15 @@ void JsonWriter::writeString(char const* value)
void JsonWriter::writeInteger(long value)
{
- _length += _sink.print(value);
+ _length += _sink->print(value);
}
void JsonWriter::writeBoolean(bool value)
{
- _length += _sink.print(value ? "true" : "false");
+ _length += _sink->print(value ? "true" : "false");
}
void JsonWriter::writeDouble(double value, int decimals)
{
- _length += _sink.print(value, decimals);
+ _length += _sink->print(value, decimals);
}
\ No newline at end of file
diff --git a/srcs/Internals/JsonWriter.h b/srcs/Internals/JsonWriter.h
index 5dfc6b5b..f1ce846c 100644
--- a/srcs/Internals/JsonWriter.h
+++ b/srcs/Internals/JsonWriter.h
@@ -5,7 +5,7 @@
class JsonWriter
{
public:
- explicit JsonWriter(Print& sink)
+ explicit JsonWriter(Print* sink)
: _sink(sink), _length(0)
{
}
@@ -34,16 +34,16 @@ public:
void writeEmptyArray()
{
- _length += _sink.print("[]");
+ _length += _sink->print("[]");
}
void writeEmptyObject()
{
- _length += _sink.print("{}");
+ _length += _sink->print("{}");
}
protected:
- Print& _sink;
+ Print* _sink;
size_t _length;
};
diff --git a/srcs/Internals/PrettyJsonWriter.h b/srcs/Internals/PrettyJsonWriter.h
index b565697d..8452c8ba 100644
--- a/srcs/Internals/PrettyJsonWriter.h
+++ b/srcs/Internals/PrettyJsonWriter.h
@@ -8,58 +8,58 @@ using namespace ArduinoJson::Generator;
class PrettyJsonWriter : public JsonWriter
{
public:
- explicit PrettyJsonWriter(IndentedPrint& sink)
+ explicit PrettyJsonWriter(IndentedPrint* sink)
: JsonWriter(sink), _indenter(sink)
{
}
virtual void beginArray()
{
- _length += _sink.write('[');
+ _length += _sink->write('[');
indent();
}
virtual void endArray()
{
unindent();
- _length += _sink.write(']');
+ _length += _sink->write(']');
}
virtual void writeColon()
{
- _length += _sink.print(": ");
+ _length += _sink->print(": ");
}
virtual void writeComma()
{
- _length += _sink.write(',');
- _length += _indenter.println();
+ _length += _sink->write(',');
+ _length += _indenter->println();
}
virtual void beginObject()
{
- _length += _sink.write('{');
+ _length += _sink->write('{');
indent();
}
virtual void endObject()
{
unindent();
- _length += _sink.write('}');
+ _length += _sink->write('}');
}
private:
- IndentedPrint& _indenter;
+ IndentedPrint* _indenter;
void indent()
{
- _indenter.indent();
- _length += _indenter.println();
+ _indenter->indent();
+ _length += _indenter->println();
}
void unindent()
{
- _length += _indenter.println();
- _indenter.unindent();
+ _length += _indenter->println();
+ _indenter->unindent();
}
};
diff --git a/srcs/JsonContainer.cpp b/srcs/JsonContainer.cpp
index 3157437d..6996e1bc 100644
--- a/srcs/JsonContainer.cpp
+++ b/srcs/JsonContainer.cpp
@@ -15,7 +15,7 @@ size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const
size_t JsonContainer::printTo(Print& p) const
{
- CompactJsonWriter writer(p);
+ CompactJsonWriter writer(&p);
_node->writeTo(writer);
return writer.bytesWritten();
}
@@ -28,11 +28,17 @@ size_t JsonContainer::prettyPrintTo(char* buffer, size_t bufferSize) const
size_t JsonContainer::prettyPrintTo(IndentedPrint& p) const
{
- PrettyJsonWriter writer(p);
+ PrettyJsonWriter writer(&p);
_node->writeTo(writer);
return writer.bytesWritten();
}
+size_t JsonContainer::prettyPrintTo(Print& print) const
+{
+ IndentedPrint indentedPrint = IndentedPrint(print);
+ return prettyPrintTo(indentedPrint);
+}
+
JsonNode* JsonContainer::createNode()
{
if (!_node) return 0;
diff --git a/srcs/JsonContainer.h b/srcs/JsonContainer.h
index 028be531..c320c5a0 100644
--- a/srcs/JsonContainer.h
+++ b/srcs/JsonContainer.h
@@ -33,10 +33,7 @@ public:
size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
size_t prettyPrintTo(ArduinoJson::Generator::IndentedPrint& print) const;
- size_t prettyPrintTo(Print& print) const
- {
- return prettyPrintTo(ArduinoJson::Generator::IndentedPrint(print));
- }
+ size_t prettyPrintTo(Print& print) const;
protected:
diff --git a/srcs/srcs.vcxproj b/srcs/srcs.vcxproj
index 2b1866cb..02869a91 100644
--- a/srcs/srcs.vcxproj
+++ b/srcs/srcs.vcxproj
@@ -49,7 +49,7 @@
- Level3
+ Level4
Disabled
true
_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
@@ -60,7 +60,7 @@
- Level3
+ Level4
MaxSpeed
true
true
diff --git a/tests/EscapedStringTests.cpp b/tests/EscapedStringTests.cpp
index 00805335..58f13578 100644
--- a/tests/EscapedStringTests.cpp
+++ b/tests/EscapedStringTests.cpp
@@ -11,7 +11,7 @@ protected:
void whenInputIs(const char* input)
{
StringBuilder sb(buffer, sizeof(buffer));
- returnValue = EscapedString::printTo(input, sb);
+ returnValue = EscapedString::printTo(input, &sb);
}
void outputMustBe(const char* expected)