Extract StringNode.hpp

This commit is contained in:
Benoit Blanchon
2023-05-22 09:05:48 +02:00
parent 044a4753d2
commit aba8974148
3 changed files with 27 additions and 12 deletions

View File

@ -6,6 +6,7 @@
#include <ArduinoJson/Memory/Alignment.hpp>
#include <ArduinoJson/Memory/Allocator.hpp>
#include <ArduinoJson/Memory/StringNode.hpp>
#include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/mpl/max.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
@ -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())

View File

@ -0,0 +1,25 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <stdint.h> // 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

View File

@ -4,6 +4,7 @@
#pragma once
#include <ArduinoJson/Memory/StringNode.hpp>
#include <ArduinoJson/Misc/SerializedValue.hpp>
#include <ArduinoJson/Numbers/convertNumber.hpp>
#include <ArduinoJson/Strings/JsonString.hpp>