2014-10-01 16:13:36 +02:00
|
|
|
#include "JsonContainer.h"
|
|
|
|
|
2014-10-01 16:56:22 +02:00
|
|
|
#include "JsonBuffer.h"
|
2014-10-01 16:13:36 +02:00
|
|
|
#include "Internals/StringBuilder.h"
|
2014-10-07 11:22:10 +02:00
|
|
|
#include "Internals/CompactJsonWriter.h"
|
|
|
|
#include "Internals/PrettyJsonWriter.h"
|
|
|
|
|
|
|
|
using namespace ArduinoJson::Internals;
|
2014-10-01 16:13:36 +02:00
|
|
|
|
|
|
|
size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const
|
|
|
|
{
|
2014-10-07 11:22:10 +02:00
|
|
|
StringBuilder sb(buffer, bufferSize);
|
2014-10-01 16:13:36 +02:00
|
|
|
return printTo(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonContainer::printTo(Print& p) const
|
|
|
|
{
|
2014-10-07 11:22:10 +02:00
|
|
|
CompactJsonWriter writer(p);
|
|
|
|
_node->writeTo(writer);
|
|
|
|
return writer.bytesWritten();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonContainer::prettyPrintTo(char* buffer, size_t bufferSize) const
|
|
|
|
{
|
|
|
|
StringBuilder sb(buffer, bufferSize);
|
|
|
|
return prettyPrintTo(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonContainer::prettyPrintTo(IndentedPrint& p) const
|
|
|
|
{
|
|
|
|
PrettyJsonWriter writer(p);
|
2014-10-05 16:25:49 +02:00
|
|
|
_node->writeTo(writer);
|
|
|
|
return writer.bytesWritten();
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 14:17:09 +02:00
|
|
|
JsonNode* JsonContainer::createNode()
|
2014-10-01 16:56:22 +02:00
|
|
|
{
|
2014-10-07 11:22:10 +02:00
|
|
|
if (!_node) return 0;
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonBuffer* buffer = _node->getContainerBuffer();
|
|
|
|
if (!buffer) return 0;
|
|
|
|
|
2014-10-09 14:17:09 +02:00
|
|
|
return buffer->createNode();
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonContainer::operator==(const JsonContainer & other) const
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return _node->getContainerChild() == other._node->getContainerChild();
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
void JsonContainer::addChild(JsonNode* childToAdd)
|
2014-10-01 16:56:22 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (_node)
|
|
|
|
_node->addChildToContainer(childToAdd);
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
void JsonContainer::removeChild(JsonNode* childToRemove)
|
2014-10-01 16:56:22 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (_node)
|
|
|
|
_node->removeChildFromContainer(childToRemove);
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonContainer::size() const
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
|
|
|
|
{
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|