From aba897414852a1071d8b3817a737f623c4ce72fd Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 22 May 2023 09:05:48 +0200 Subject: [PATCH] Extract `StringNode.hpp` --- src/ArduinoJson/Memory/MemoryPool.hpp | 13 +------------ src/ArduinoJson/Memory/StringNode.hpp | 25 +++++++++++++++++++++++++ src/ArduinoJson/Variant/VariantData.hpp | 1 + 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 src/ArduinoJson/Memory/StringNode.hpp diff --git a/src/ArduinoJson/Memory/MemoryPool.hpp b/src/ArduinoJson/Memory/MemoryPool.hpp index 42df6c81..2324e1ba 100644 --- a/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/src/ArduinoJson/Memory/MemoryPool.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -25,18 +26,6 @@ constexpr size_t sizeofObject(size_t n) { return n * sizeof(VariantSlot); } -struct StringNode { - struct StringNode* next; - uint16_t length; - uint16_t references; - char data[1]; -}; - -// Returns the size (in bytes) of an string with n characters. -constexpr size_t sizeofString(size_t n) { - return n + 1 + offsetof(StringNode, data); -} - class MemoryPool { public: MemoryPool(size_t capa, Allocator* allocator = DefaultAllocator::instance()) diff --git a/src/ArduinoJson/Memory/StringNode.hpp b/src/ArduinoJson/Memory/StringNode.hpp new file mode 100644 index 00000000..b1c7e0e3 --- /dev/null +++ b/src/ArduinoJson/Memory/StringNode.hpp @@ -0,0 +1,25 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +#pragma once + +#include + +#include // uint16_t + +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + +struct StringNode { + struct StringNode* next; + uint16_t length; + uint16_t references; + char data[1]; +}; + +// Returns the size (in bytes) of an string with n characters. +constexpr size_t sizeofString(size_t n) { + return n + 1 + offsetof(StringNode, data); +} + +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/src/ArduinoJson/Variant/VariantData.hpp b/src/ArduinoJson/Variant/VariantData.hpp index 00be130a..c70ebd42 100644 --- a/src/ArduinoJson/Variant/VariantData.hpp +++ b/src/ArduinoJson/Variant/VariantData.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include