forked from bblanchon/ArduinoJson
Implement Printable
This commit is contained in:
@ -9,33 +9,6 @@
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
//JsonValue& JsonObject::operator[](char const* key)
|
||||
//{
|
||||
// addNodeAt(key, innerObject._node);
|
||||
// return innerObject;
|
||||
//}
|
||||
//
|
||||
//void JsonObject::addNodeAt(const char* key, JsonNode& node)
|
||||
//{
|
||||
// JsonNode& keyNode = _buffer.createNode();
|
||||
// keyNode.becomeKey(key, node);
|
||||
// appendChild(keyNode);
|
||||
//}
|
||||
//
|
||||
//void JsonObject::appendChild(JsonNode& newChild)
|
||||
//{
|
||||
// JsonNode* lastChild = _node.asObjectNode.child;
|
||||
// while (lastChild->next)
|
||||
// {
|
||||
// lastChild = lastChild->next;
|
||||
// }
|
||||
//
|
||||
// if (lastChild)
|
||||
// lastChild->next = &newChild;
|
||||
// else
|
||||
// _node.asObjectNode.child = &newChild;
|
||||
//}
|
||||
|
||||
size_t JsonObject::size()
|
||||
{
|
||||
JsonNode* firstChild = _node->content.asObject.child;
|
||||
@ -94,13 +67,13 @@ JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
|
||||
return newValueNode;
|
||||
}
|
||||
|
||||
void JsonObject::printTo(char* buffer, size_t bufferSize) const
|
||||
size_t JsonObject::printTo(char* buffer, size_t bufferSize) const
|
||||
{
|
||||
StringBuilder sb(buffer, bufferSize);
|
||||
printTo(sb);
|
||||
return printTo(sb);
|
||||
}
|
||||
|
||||
void JsonObject::printTo(Print& p) const
|
||||
size_t JsonObject::printTo(Print& p) const
|
||||
{
|
||||
p.print("{}");
|
||||
return p.print("{}");
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
class JsonValue;
|
||||
struct JsonNode;
|
||||
|
||||
class JsonObject
|
||||
class JsonObject : public Printable
|
||||
{
|
||||
friend JsonValue;
|
||||
|
||||
@ -26,8 +26,8 @@ public:
|
||||
|
||||
bool operator==(const JsonObject& other) const;
|
||||
|
||||
void printTo(char* buffer, size_t bufferSize) const;
|
||||
void printTo(Print& print) const;
|
||||
size_t printTo(char* buffer, size_t bufferSize) const;
|
||||
virtual size_t printTo(Print& print) const;
|
||||
|
||||
private:
|
||||
JsonNode* _node;
|
||||
|
24
srcs/Printable.h
Normal file
24
srcs/Printable.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ARDUINO
|
||||
|
||||
class Print;
|
||||
|
||||
class Printable
|
||||
{
|
||||
public:
|
||||
|
||||
virtual size_t printTo(Print& p) const = 0;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#include <Printable.h>
|
||||
|
||||
#endif
|
||||
|
@ -72,6 +72,7 @@
|
||||
<ClInclude Include="JsonObject.h" />
|
||||
<ClInclude Include="JsonValue.h" />
|
||||
<ClInclude Include="Print.h" />
|
||||
<ClInclude Include="Printable.h" />
|
||||
<ClInclude Include="StaticJsonBuffer.h" />
|
||||
<ClInclude Include="StringBuilder.h" />
|
||||
</ItemGroup>
|
||||
|
@ -36,6 +36,9 @@
|
||||
<ClInclude Include="Print.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Printable.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="JsonObject.cpp">
|
||||
|
@ -13,9 +13,10 @@ protected:
|
||||
void jsonMustBe(const char* expected)
|
||||
{
|
||||
char actual[256];
|
||||
object.printTo(actual, sizeof(actual));
|
||||
int result = object.printTo(actual, sizeof(actual));
|
||||
|
||||
EXPECT_STREQ(expected, actual);
|
||||
EXPECT_EQ(strlen(expected), result);
|
||||
}
|
||||
|
||||
JsonObject object;
|
||||
|
Reference in New Issue
Block a user