Files
ArduinoJson/src/Internals/JsonValueImpl.cpp

46 lines
1.1 KiB
C++
Raw Normal View History

2014-10-27 13:34:54 +01:00
// Copyright Benoit Blanchon 2014
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#include "ArduinoJson/Internals/JsonValueImpl.hpp"
2014-10-27 22:50:50 +01:00
#include "ArduinoJson/Internals/JsonArrayImpl.hpp"
#include "ArduinoJson/Internals/JsonObjectImpl.hpp"
#include "ArduinoJson/Internals/JsonWriter.hpp"
2014-10-28 16:29:55 +01:00
using namespace ArduinoJson;
2014-10-27 22:50:50 +01:00
using namespace ArduinoJson::Internals;
2014-10-27 13:34:54 +01:00
2014-10-28 16:29:55 +01:00
JsonValueImpl* JsonValueImpl::createFrom(JsonBuffer* buffer) {
void* ptr = buffer->alloc(sizeof(JsonValueImpl));
return ptr ? new (ptr) JsonValueImpl() : NULL;
}
void JsonValueImpl::writeTo(JsonWriter& writer) const {
2014-10-27 13:34:54 +01:00
switch (_type) {
case JSON_ARRAY:
_content.asArray->writeTo(writer);
break;
case JSON_OBJECT:
_content.asObject->writeTo(writer);
break;
case JSON_STRING:
2014-10-27 22:50:50 +01:00
writer.writeString(_content.asString);
2014-10-27 13:34:54 +01:00
break;
case JSON_LONG:
2014-10-27 22:50:50 +01:00
writer.writeInteger(_content.asInteger);
2014-10-27 13:34:54 +01:00
break;
case JSON_BOOLEAN:
2014-10-27 22:50:50 +01:00
writer.writeBoolean(_content.asBoolean);
2014-10-27 13:34:54 +01:00
break;
default: // >= JSON_DOUBLE_0_DECIMALS
2014-10-27 22:50:50 +01:00
writer.writeDouble(_content.asDouble, _type - JSON_DOUBLE_0_DECIMALS);
2014-10-27 13:34:54 +01:00
break;
}
}