forked from bblanchon/ArduinoJson
Improved test printers
This commit is contained in:
@ -11,17 +11,14 @@
|
|||||||
|
|
||||||
#include "Internals/JsonVariantContent.hpp"
|
#include "Internals/JsonVariantContent.hpp"
|
||||||
#include "Internals/JsonVariantType.hpp"
|
#include "Internals/JsonVariantType.hpp"
|
||||||
|
#include "JsonPrintable.hpp"
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
|
|
||||||
class JsonArray;
|
class JsonArray;
|
||||||
class JsonObject;
|
class JsonObject;
|
||||||
|
|
||||||
namespace Internals {
|
class JsonVariant : public JsonPrintable<JsonVariant> {
|
||||||
class JsonWriter;
|
|
||||||
}
|
|
||||||
|
|
||||||
class JsonVariant {
|
|
||||||
public:
|
public:
|
||||||
JsonVariant() : _type(Internals::JSON_UNDEFINED) {}
|
JsonVariant() : _type(Internals::JSON_UNDEFINED) {}
|
||||||
|
|
||||||
|
@ -5,14 +5,31 @@
|
|||||||
// https://github.com/bblanchon/ArduinoJson
|
// https://github.com/bblanchon/ArduinoJson
|
||||||
|
|
||||||
#include "Printers.hpp"
|
#include "Printers.hpp"
|
||||||
|
#include <ArduinoJson/JsonArray.hpp>
|
||||||
|
|
||||||
|
class StreamPrintAdapter : public Print {
|
||||||
|
public:
|
||||||
|
StreamPrintAdapter(std::ostream& os) : _os(os) {}
|
||||||
|
|
||||||
|
virtual size_t write(uint8_t c) {
|
||||||
|
_os << (char)c;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ostream& _os;
|
||||||
|
};
|
||||||
|
|
||||||
std::ostream& ArduinoJson::operator<<(std::ostream& os,
|
std::ostream& ArduinoJson::operator<<(std::ostream& os,
|
||||||
const ArduinoJson::JsonVariant& v) {
|
const ArduinoJson::JsonVariant& v) {
|
||||||
if (v.is<long>())
|
StreamPrintAdapter adapter(os);
|
||||||
os << v.as<long>();
|
v.printTo(adapter);
|
||||||
else if (v.is<double>())
|
return os;
|
||||||
os << v.as<double>();
|
}
|
||||||
else
|
|
||||||
os << "JsonVariant"; // TODO
|
std::ostream& ArduinoJson::operator<<(std::ostream& os,
|
||||||
|
const ArduinoJson::JsonArray& v) {
|
||||||
|
StreamPrintAdapter adapter(os);
|
||||||
|
v.printTo(adapter);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,5 @@
|
|||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
std::ostream& operator<<(std::ostream& os, const ArduinoJson::JsonVariant& v);
|
std::ostream& operator<<(std::ostream& os, const ArduinoJson::JsonVariant& v);
|
||||||
|
std::ostream& operator<<(std::ostream& os, const ArduinoJson::JsonArray& v);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user