Files
ArduinoJson/JsonGeneratorTests/JsonObjectBase.h

49 lines
830 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-25 13:33:19 +02:00
enum ObjectType
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-25 13:33:19 +02:00
union ObjectValue
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-25 13:33:19 +02:00
struct ObjectContainer
2014-06-25 13:23:08 +02:00
{
2014-06-25 13:33:19 +02:00
ObjectType type;
ObjectValue value;
2014-06-25 13:23:08 +02:00
};
2014-06-25 13:34:47 +02:00
void writeObjectTo(ObjectContainer& 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
};