diff --git a/src/ArduinoJson/Configuration.hpp b/src/ArduinoJson/Configuration.hpp index 2b7ac2c1..cfeed81d 100644 --- a/src/ArduinoJson/Configuration.hpp +++ b/src/ArduinoJson/Configuration.hpp @@ -122,6 +122,15 @@ # endif #endif +// Number of bytes to store the length of a string +#ifndef ARDUINOJSON_STRING_LENGTH_SIZE +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_STRING_LENGTH_SIZE 1 // up to 255 characters +# else +# define ARDUINOJSON_STRING_LENGTH_SIZE 2 // up to 65535 characters +# endif +#endif + #ifdef ARDUINO // Enable support for Arduino's String class diff --git a/src/ArduinoJson/Memory/StringNode.hpp b/src/ArduinoJson/Memory/StringNode.hpp index 88979cd7..44254a87 100644 --- a/src/ArduinoJson/Memory/StringNode.hpp +++ b/src/ArduinoJson/Memory/StringNode.hpp @@ -11,7 +11,6 @@ #include #include // offsetof -#include // uint16_t ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE @@ -20,12 +19,14 @@ struct StringNode { // (there can never be more references than slots) using references_type = uint_t::type; + using length_type = uint_t::type; + struct StringNode* next; - uint16_t length; + length_type length; references_type references; char data[1]; - static constexpr size_t maxLength = numeric_limits::highest(); + static constexpr size_t maxLength = numeric_limits::highest(); static constexpr size_t sizeForLength(size_t n) { return n + 1 + offsetof(StringNode, data); @@ -37,7 +38,7 @@ struct StringNode { auto node = reinterpret_cast( allocator->allocate(sizeForLength(length))); if (node) { - node->length = uint16_t(length); + node->length = length_type(length); node->references = 1; } return node; @@ -53,7 +54,7 @@ struct StringNode { else newNode = nullptr; if (newNode) - newNode->length = uint16_t(length); + newNode->length = length_type(length); else allocator->deallocate(node); return newNode;