forked from bblanchon/ArduinoJson
Added a test that stores a long in a JsonValue
This commit is contained in:
@ -14,13 +14,23 @@ size_t JsonValue::printBoolTo(Print& p) const
|
||||
|
||||
size_t JsonValue::printDoubleTo(Print& p) const
|
||||
{
|
||||
char tmp[16];
|
||||
char tmp[32];
|
||||
|
||||
sprintf(tmp, "%lg", content.asDouble);
|
||||
|
||||
return p.write(tmp);
|
||||
}
|
||||
|
||||
size_t JsonValue::printLongTo(Print& p) const
|
||||
{
|
||||
char tmp[32];
|
||||
|
||||
sprintf(tmp, "%ld", content.asLong);
|
||||
|
||||
return p.write(tmp);
|
||||
}
|
||||
|
||||
|
||||
size_t JsonValue::printPrintableTo(Print& p) const
|
||||
{
|
||||
if (content.asPrintable)
|
||||
|
@ -16,10 +16,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
JsonValue(const char* value)
|
||||
: implementation(&JsonValue::printStringTo)
|
||||
JsonValue(bool value)
|
||||
: implementation(&JsonValue::printBoolTo)
|
||||
{
|
||||
content.asString = value;
|
||||
content.asBool = value;
|
||||
}
|
||||
|
||||
JsonValue(double value)
|
||||
@ -28,10 +28,10 @@ public:
|
||||
content.asDouble = value;
|
||||
}
|
||||
|
||||
JsonValue(bool value)
|
||||
: implementation(&JsonValue::printBoolTo)
|
||||
JsonValue(long value)
|
||||
: implementation(&JsonValue::printLongTo)
|
||||
{
|
||||
content.asBool = value;
|
||||
content.asLong = value;
|
||||
}
|
||||
|
||||
JsonValue(Printable& value)
|
||||
@ -40,6 +40,12 @@ public:
|
||||
content.asPrintable = &value;
|
||||
}
|
||||
|
||||
JsonValue(const char* value)
|
||||
: implementation(&JsonValue::printStringTo)
|
||||
{
|
||||
content.asString = value;
|
||||
}
|
||||
|
||||
virtual size_t printTo(Print& p) const
|
||||
{
|
||||
// handmade polymorphism
|
||||
@ -52,6 +58,7 @@ private:
|
||||
{
|
||||
bool asBool;
|
||||
double asDouble;
|
||||
long asLong;
|
||||
Printable* asPrintable;
|
||||
const char* asString;
|
||||
};
|
||||
@ -62,6 +69,7 @@ private:
|
||||
|
||||
size_t printBoolTo(Print& p) const;
|
||||
size_t printDoubleTo(Print& p) const;
|
||||
size_t printLongTo(Print& p) const;
|
||||
size_t printPrintableTo(Print& p) const;
|
||||
size_t printStringTo(Print& p) const;
|
||||
};
|
Reference in New Issue
Block a user