forked from bblanchon/ArduinoJson
Simplified JsonWriter hierarchy
This commit is contained in:
@ -1,28 +0,0 @@
|
|||||||
// Copyright Benoit Blanchon 2014
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Arduino JSON library
|
|
||||||
// https://github.com/bblanchon/ArduinoJson
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "JsonWriter.hpp"
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
|
||||||
namespace Internals {
|
|
||||||
|
|
||||||
class CompactJsonWriter : public JsonWriter {
|
|
||||||
public:
|
|
||||||
explicit CompactJsonWriter(Print *sink) : JsonWriter(sink) {}
|
|
||||||
|
|
||||||
void beginArray() { _length += _sink->write('['); }
|
|
||||||
void endArray() { _length += _sink->write(']'); }
|
|
||||||
|
|
||||||
void beginObject() { _length += _sink->write('{'); }
|
|
||||||
void endObject() { _length += _sink->write('}'); }
|
|
||||||
|
|
||||||
void writeColon() { _length += _sink->write(':'); }
|
|
||||||
void writeComma() { _length += _sink->write(','); }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,8 +17,12 @@ class JsonWriter {
|
|||||||
|
|
||||||
size_t bytesWritten() { return _length; }
|
size_t bytesWritten() { return _length; }
|
||||||
|
|
||||||
|
void beginArray() { _length += _sink->write('['); }
|
||||||
|
void endArray() { _length += _sink->write(']'); }
|
||||||
void writeEmptyArray() { _length += _sink->print("[]"); }
|
void writeEmptyArray() { _length += _sink->print("[]"); }
|
||||||
|
|
||||||
|
void beginObject() { _length += _sink->write('{'); }
|
||||||
|
void endObject() { _length += _sink->write('}'); }
|
||||||
void writeEmptyObject() { _length += _sink->print("{}"); }
|
void writeEmptyObject() { _length += _sink->print("{}"); }
|
||||||
|
|
||||||
void writeString(const char *value);
|
void writeString(const char *value);
|
||||||
@ -26,6 +30,9 @@ class JsonWriter {
|
|||||||
void writeBoolean(bool value);
|
void writeBoolean(bool value);
|
||||||
void writeDouble(double value, int decimals);
|
void writeDouble(double value, int decimals);
|
||||||
|
|
||||||
|
void writeColon() { _length += _sink->write(':'); }
|
||||||
|
void writeComma() { _length += _sink->write(','); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Print *_sink;
|
Print *_sink;
|
||||||
size_t _length;
|
size_t _length;
|
||||||
|
@ -6,19 +6,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Arduino/Printable.hpp"
|
|
||||||
#include "Internals/StringBuilder.hpp"
|
#include "Internals/StringBuilder.hpp"
|
||||||
#include "Internals/IndentedPrint.hpp"
|
#include "Internals/IndentedPrint.hpp"
|
||||||
#include "Internals/CompactJsonWriter.hpp"
|
|
||||||
#include "Internals/PrettyJsonWriter.hpp"
|
#include "Internals/PrettyJsonWriter.hpp"
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class JsonPrintable : public Printable {
|
class JsonPrintable {
|
||||||
public:
|
public:
|
||||||
size_t printTo(Print &print) const {
|
size_t printTo(Print &print) const {
|
||||||
Internals::CompactJsonWriter writer(&print);
|
Internals::JsonWriter writer(&print);
|
||||||
downcast().writeTo(writer);
|
downcast().writeTo(writer);
|
||||||
return writer.bytesWritten();
|
return writer.bytesWritten();
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include "ArduinoJson/JsonBuffer.hpp"
|
#include "ArduinoJson/JsonBuffer.hpp"
|
||||||
#include "ArduinoJson/JsonObject.hpp"
|
#include "ArduinoJson/JsonObject.hpp"
|
||||||
#include "ArduinoJson/Internals/CompactJsonWriter.hpp"
|
|
||||||
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||||
|
|
||||||
using namespace ArduinoJson;
|
using namespace ArduinoJson;
|
||||||
@ -91,5 +90,5 @@ void JsonArray::writeTo(T &writer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template void JsonArray::writeTo<CompactJsonWriter>(CompactJsonWriter &) const;
|
template void JsonArray::writeTo(JsonWriter &) const;
|
||||||
template void JsonArray::writeTo<PrettyJsonWriter>(PrettyJsonWriter &) const;
|
template void JsonArray::writeTo(PrettyJsonWriter &) const;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "ArduinoJson/JsonBuffer.hpp"
|
#include "ArduinoJson/JsonBuffer.hpp"
|
||||||
#include "ArduinoJson/JsonArray.hpp"
|
#include "ArduinoJson/JsonArray.hpp"
|
||||||
#include "ArduinoJson/JsonValue.hpp"
|
#include "ArduinoJson/JsonValue.hpp"
|
||||||
#include "ArduinoJson/Internals/CompactJsonWriter.hpp"
|
|
||||||
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||||
#include "ArduinoJson/Internals/StringBuilder.hpp"
|
#include "ArduinoJson/Internals/StringBuilder.hpp"
|
||||||
|
|
||||||
@ -116,5 +115,5 @@ void JsonObject::writeTo(T &writer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template void JsonObject::writeTo(CompactJsonWriter &writer) const;
|
template void JsonObject::writeTo(JsonWriter &writer) const;
|
||||||
template void JsonObject::writeTo(PrettyJsonWriter &writer) const;
|
template void JsonObject::writeTo(PrettyJsonWriter &writer) const;
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright Benoit Blanchon 2014
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Arduino JSON library
|
|
||||||
// https://github.com/bblanchon/ArduinoJson
|
|
||||||
|
|
||||||
#include "ArduinoJson/JsonPrintable.hpp"
|
|
||||||
|
|
||||||
#include "ArduinoJson/JsonBuffer.hpp"
|
|
||||||
#include "ArduinoJson/Internals/StringBuilder.hpp"
|
|
||||||
#include "ArduinoJson/Internals/CompactJsonWriter.hpp"
|
|
||||||
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
|
||||||
|
|
||||||
using namespace ArduinoJson;
|
|
||||||
using namespace ArduinoJson::Internals;
|
|
@ -7,7 +7,6 @@
|
|||||||
#include "ArduinoJson/JsonValue.hpp"
|
#include "ArduinoJson/JsonValue.hpp"
|
||||||
#include "ArduinoJson/JsonArray.hpp"
|
#include "ArduinoJson/JsonArray.hpp"
|
||||||
#include "ArduinoJson/JsonObject.hpp"
|
#include "ArduinoJson/JsonObject.hpp"
|
||||||
#include "ArduinoJson/Internals/CompactJsonWriter.hpp"
|
|
||||||
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||||
|
|
||||||
using namespace ArduinoJson;
|
using namespace ArduinoJson;
|
||||||
@ -104,5 +103,5 @@ void JsonValue::writeTo(T &writer) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template void JsonValue::writeTo<CompactJsonWriter>(CompactJsonWriter &) const;
|
template void JsonValue::writeTo(JsonWriter &) const;
|
||||||
template void JsonValue::writeTo<PrettyJsonWriter>(PrettyJsonWriter &) const;
|
template void JsonValue::writeTo(PrettyJsonWriter &) const;
|
||||||
|
Reference in New Issue
Block a user