mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-02 00:38:26 +01:00
Removed friend relationship between JsonVariant and JsonSerializer
This commit is contained in:
@@ -36,6 +36,47 @@ class JsonSerializer {
|
||||
template <typename TKey>
|
||||
static void serialize(const JsonObjectSubscript<TKey> &, Writer &);
|
||||
static void serialize(const JsonVariant &, Writer &);
|
||||
|
||||
struct Visitor {
|
||||
Visitor(Writer *writer) : _writer(writer) {}
|
||||
|
||||
void acceptFloat(JsonFloat value) {
|
||||
_writer->writeFloat(value);
|
||||
}
|
||||
|
||||
void acceptArray(const JsonArray &value) {
|
||||
serialize(value, *_writer);
|
||||
}
|
||||
|
||||
void acceptObject(const JsonObject &value) {
|
||||
serialize(value, *_writer);
|
||||
}
|
||||
|
||||
void acceptString(const char *value) {
|
||||
_writer->writeString(value);
|
||||
}
|
||||
|
||||
void acceptRawJson(const char *value) {
|
||||
_writer->writeRaw(value);
|
||||
}
|
||||
|
||||
void acceptNegativeInteger(JsonUInt value) {
|
||||
_writer->writeRaw('-');
|
||||
_writer->writeInteger(value);
|
||||
}
|
||||
|
||||
void acceptPositiveInteger(JsonUInt value) {
|
||||
_writer->writeInteger(value);
|
||||
}
|
||||
|
||||
void acceptBoolean(bool value) {
|
||||
_writer->writeBoolean(value);
|
||||
}
|
||||
|
||||
void acceptUndefined() {}
|
||||
|
||||
Writer *_writer;
|
||||
};
|
||||
};
|
||||
} // namespace Internals
|
||||
|
||||
|
||||
@@ -65,39 +65,5 @@ inline void ArduinoJson::Internals::JsonSerializer<Writer>::serialize(
|
||||
template <typename Writer>
|
||||
inline void ArduinoJson::Internals::JsonSerializer<Writer>::serialize(
|
||||
const JsonVariant& variant, Writer& writer) {
|
||||
switch (variant._type) {
|
||||
case JSON_FLOAT:
|
||||
writer.writeFloat(variant._content.asFloat);
|
||||
return;
|
||||
|
||||
case JSON_ARRAY:
|
||||
serialize(*variant._content.asArray, writer);
|
||||
return;
|
||||
|
||||
case JSON_OBJECT:
|
||||
serialize(*variant._content.asObject, writer);
|
||||
return;
|
||||
|
||||
case JSON_STRING:
|
||||
writer.writeString(variant._content.asString);
|
||||
return;
|
||||
|
||||
case JSON_UNPARSED:
|
||||
writer.writeRaw(variant._content.asString);
|
||||
return;
|
||||
|
||||
case JSON_NEGATIVE_INTEGER:
|
||||
writer.writeRaw('-'); // Falls through.
|
||||
|
||||
case JSON_POSITIVE_INTEGER:
|
||||
writer.writeInteger(variant._content.asInteger);
|
||||
return;
|
||||
|
||||
case JSON_BOOLEAN:
|
||||
writer.writeBoolean(variant._content.asInteger != 0);
|
||||
return;
|
||||
|
||||
default: // JSON_UNDEFINED
|
||||
return;
|
||||
}
|
||||
variant.visit(Visitor(&writer));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user