diff --git a/include/ArduinoJson/DynamicJsonBuffer.hpp b/include/ArduinoJson/DynamicJsonBuffer.hpp new file mode 100644 index 00000000..5c42a02a --- /dev/null +++ b/include/ArduinoJson/DynamicJsonBuffer.hpp @@ -0,0 +1,25 @@ +// Copyright Benoit Blanchon 2014 +// MIT License +// +// Arduino JSON library +// https://github.com/bblanchon/ArduinoJson + +#pragma once + +#include "JsonBuffer.hpp" + +namespace ArduinoJson { + +// Implements a JsonBuffer with dynamic memory allocation. +// You are strongly encouraged to consider using StaticJsonBuffer which is much +// more suitable for embedded systems. +class DynamicJsonBuffer : public JsonBuffer { + public: + explicit DynamicJsonBuffer() {} + + size_t size() const { return 0; } + + protected: + virtual void* alloc(size_t bytes) { return NULL; } +}; +} diff --git a/test/DynamicJsonBuffer_Basic_Tests.cpp b/test/DynamicJsonBuffer_Basic_Tests.cpp new file mode 100644 index 00000000..a506d003 --- /dev/null +++ b/test/DynamicJsonBuffer_Basic_Tests.cpp @@ -0,0 +1,21 @@ +// Copyright Benoit Blanchon 2014 +// MIT License +// +// Arduino JSON library +// https://github.com/bblanchon/ArduinoJson + +#include + +#define protected public +#include + +using namespace ArduinoJson; + +class DynamicJsonBuffer_Basic_Tests : public testing::Test { + protected: + DynamicJsonBuffer buffer; +}; + +TEST_F(DynamicJsonBuffer_Basic_Tests, InitialSizeIsZero) { + ASSERT_EQ(0, buffer.size()); +}