Files
ArduinoJson/JsonGeneratorTests/JsonObjectBase.h

49 lines
838 B
C
Raw Normal View History

2014-06-25 13:23:08 +02:00
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#pragma once
#include "StringBuilder.h"
class JsonObjectBase
{
public:
2014-06-26 13:39:05 +02:00
void writeTo(char* buffer, size_t bufferSize)
{
StringBuilder sb(buffer, bufferSize);
writeTo(sb);
}
2014-06-25 13:23:08 +02:00
protected:
2014-06-27 13:18:38 +02:00
enum JsonValueType
2014-06-25 13:23:08 +02:00
{
JSON_STRING,
JSON_NUMBER,
JSON_BOOLEAN,
JSON_OBJECT,
2014-06-25 13:23:08 +02:00
};
2014-06-27 13:18:38 +02:00
union JsonValueContent
2014-06-25 13:23:08 +02:00
{
const char* string;
double number;
bool boolean;
JsonObjectBase* object;
2014-06-25 13:23:08 +02:00
};
2014-06-27 13:18:38 +02:00
struct JsonValue
2014-06-25 13:23:08 +02:00
{
2014-06-27 13:18:38 +02:00
JsonValueType type;
JsonValueContent content;
2014-06-25 13:23:08 +02:00
};
2014-06-27 13:18:38 +02:00
void writeValueTo(JsonValue& obj, StringBuilder& sb);
2014-06-25 13:34:47 +02:00
virtual void writeTo(StringBuilder& sb) = 0;
2014-06-25 13:23:08 +02:00
};