Support basic_string<char, CustomAllocator>
Created by: sticilface
Looking at the documentation this should work size_t serializeMsgPack(const JsonDocument& doc, std::string& output);
Compiling on the ESP32 Dev env within arduino.
using 815326d4
#include <string>
#include <ArduinoJson.h>
std::string jsonString;
void setup() {
DynamicJsonDocument doc(2048);
serializeMsgPack(doc, jsonString);
}
void loop() {
}
but it fails giving this error
In file included from /Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.hpp:37:0,
from /Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:9,
from /Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:2:
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp: In instantiation of 'void ArduinoJson691_000::MsgPackSerializer<TWriter>::writeByte(uint8_t) [with TWriter = std::__cxx11::basic_string<char>; uint8_t = unsigned char]':
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp:144:14: required from 'void ArduinoJson691_000::MsgPackSerializer<TWriter>::visitNull() [with TWriter = std::__cxx11::basic_string<char>]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:16:5: required from 'void ArduinoJson691_000::variantAccept(const ArduinoJson691_000::VariantData*, Visitor&) [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:347:18: required from 'void ArduinoJson691_000::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:21:39: required from 'void ArduinoJson691_000::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:21:3: required from 'typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type ArduinoJson691_000::serialize(const TSource&, TPrint&) [with TSerializer = ArduinoJson691_000::MsgPackSerializer; TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TPrint = std::__cxx11::basic_string<char>; typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp:172:38: required from 'size_t ArduinoJson691_000::serializeMsgPack(const TSource&, TDestination&) [with TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TDestination = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:15:33: required from here
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp:153:19: error: 'class std::__cxx11::basic_string<char>' has no member named 'write'
_bytesWritten += _writer->write(c);
^
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp: In instantiation of 'void ArduinoJson691_000::MsgPackSerializer<TWriter>::writeBytes(const uint8_t*, size_t) [with TWriter = std::__cxx11::basic_string<char>; uint8_t = unsigned char; size_t = unsigned int]':
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp:89:15: required from 'void ArduinoJson691_000::MsgPackSerializer<TWriter>::visitString(const char*) [with TWriter = std::__cxx11::basic_string<char>]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:39:53: required from 'void ArduinoJson691_000::VariantData::accept(Visitor&) const [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:14:5: required from 'void ArduinoJson691_000::variantAccept(const ArduinoJson691_000::VariantData*, Visitor&) [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:347:18: required from 'void ArduinoJson691_000::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:21:39: required from 'void ArduinoJson691_000::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson691_000::MsgPackSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:21:3: required from 'typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type ArduinoJson691_000::serialize(const TSource&, TPrint&) [with TSerializer = ArduinoJson691_000::MsgPackSerializer; TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TPrint = std::__cxx11::basic_string<char>; typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp:172:38: required from 'size_t ArduinoJson691_000::serializeMsgPack(const TSource&, TDestination&) [with TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TDestination = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:15:33: required from here
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp:157:19: error: 'class std::__cxx11::basic_string<char>' has no member named 'write'
_bytesWritten += _writer->write(p, n);
my actual goal is to get this to work
using PsramString = std::basic_string<char, std::char_traits<char>,spram_allocator<char>>;
so I can use the PSRAM allocator and get all the strings onto the external ram.
However, I got stuck as just trying to use std::string
This is the error for serializeJson
In file included from /Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:10:0,
from /Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.hpp:34,
from /Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:9,
from /Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:2:
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp: In instantiation of 'void ArduinoJson691_000::TextFormatter<TWriter>::writeRaw(const char*) [with TWriter = std::__cxx11::basic_string<char>]':
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:80:5: required from 'void ArduinoJson691_000::JsonSerializer<TWriter>::visitNull() [with TWriter = std::__cxx11::basic_string<char>]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:16:5: required from 'void ArduinoJson691_000::variantAccept(const ArduinoJson691_000::VariantData*, Visitor&) [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:347:18: required from 'void ArduinoJson691_000::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:21:39: required from 'void ArduinoJson691_000::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:21:3: required from 'typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type ArduinoJson691_000::serialize(const TSource&, TPrint&) [with TSerializer = ArduinoJson691_000::JsonSerializer; TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TPrint = std::__cxx11::basic_string<char>; typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:102:35: required from 'size_t ArduinoJson691_000::serializeJson(const TSource&, TDestination&) [with TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TDestination = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:15:30: required from here
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:119:13: error: 'class std::__cxx11::basic_string<char>' has no member named 'write'
_length += _writer.write(reinterpret_cast<const uint8_t *>(s), strlen(s));
^
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp: In instantiation of 'void ArduinoJson691_000::TextFormatter<TWriter>::writeRaw(const char*, size_t) [with TWriter = std::__cxx11::basic_string<char>; size_t = unsigned int]':
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:64:5: required from 'void ArduinoJson691_000::JsonSerializer<TWriter>::visitRawJson(const char*, size_t) [with TWriter = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:43:77: required from 'void ArduinoJson691_000::VariantData::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:14:5: required from 'void ArduinoJson691_000::variantAccept(const ArduinoJson691_000::VariantData*, Visitor&) [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:347:18: required from 'void ArduinoJson691_000::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:21:39: required from 'void ArduinoJson691_000::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:21:3: required from 'typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type ArduinoJson691_000::serialize(const TSource&, TPrint&) [with TSerializer = ArduinoJson691_000::JsonSerializer; TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TPrint = std::__cxx11::basic_string<char>; typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:102:35: required from 'size_t ArduinoJson691_000::serializeJson(const TSource&, TDestination&) [with TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TDestination = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:15:30: required from here
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:123:13: error: 'class std::__cxx11::basic_string<char>' has no member named 'write'
_length += _writer.write(reinterpret_cast<const uint8_t *>(s), n);
^
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp: In instantiation of 'void ArduinoJson691_000::TextFormatter<TWriter>::writeRaw(char) [with TWriter = std::__cxx11::basic_string<char>]':
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:58:15: required from 'void ArduinoJson691_000::TextFormatter<TWriter>::writeFloat(T) [with T = float; TWriter = std::__cxx11::basic_string<char>]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:56:5: required from 'void ArduinoJson691_000::JsonSerializer<TWriter>::visitFloat(ArduinoJson691_000::Float) [with TWriter = std::__cxx11::basic_string<char>; ArduinoJson691_000::Float = float]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:29:51: required from 'void ArduinoJson691_000::VariantData::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:14:5: required from 'void ArduinoJson691_000::variantAccept(const ArduinoJson691_000::VariantData*, Visitor&) [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:347:18: required from 'void ArduinoJson691_000::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:21:39: required from 'void ArduinoJson691_000::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:21:3: required from 'typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type ArduinoJson691_000::serialize(const TSource&, TPrint&) [with TSerializer = ArduinoJson691_000::JsonSerializer; TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TPrint = std::__cxx11::basic_string<char>; typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:102:35: required from 'size_t ArduinoJson691_000::serializeJson(const TSource&, TDestination&) [with TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TDestination = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:15:30: required from here
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:136:13: error: 'class std::__cxx11::basic_string<char>' has no member named 'write'
_length += _writer.write(static_cast<uint8_t>(c));
^
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp: In instantiation of 'void ArduinoJson691_000::TextFormatter<TWriter>::writeRaw(const char*, const char*) [with TWriter = std::__cxx11::basic_string<char>]':
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:98:13: required from 'void ArduinoJson691_000::TextFormatter<TWriter>::writePositiveInteger(T) [with T = long unsigned int; TWriter = std::__cxx11::basic_string<char>]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:72:5: required from 'void ArduinoJson691_000::JsonSerializer<TWriter>::visitPositiveInteger(ArduinoJson691_000::UInt) [with TWriter = std::__cxx11::basic_string<char>; ArduinoJson691_000::UInt = long unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:49:63: required from 'void ArduinoJson691_000::VariantData::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:14:5: required from 'void ArduinoJson691_000::variantAccept(const ArduinoJson691_000::VariantData*, Visitor&) [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:347:18: required from 'void ArduinoJson691_000::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:21:39: required from 'void ArduinoJson691_000::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson691_000::JsonSerializer<std::__cxx11::basic_string<char> >]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:21:3: required from 'typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type ArduinoJson691_000::serialize(const TSource&, TPrint&) [with TSerializer = ArduinoJson691_000::JsonSerializer; TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TPrint = std::__cxx11::basic_string<char>; typename ArduinoJson691_000::enable_if<(! ArduinoJson691_000::IsWriteableString<TPrint>::value), unsigned int>::type = unsigned int]'
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:102:35: required from 'size_t ArduinoJson691_000::serializeJson(const TSource&, TDestination&) [with TSource = ArduinoJson691_000::BasicJsonDocument<ArduinoJson691_000::DefaultAllocator>; TDestination = std::__cxx11::basic_string<char>; size_t = unsigned int]'
/Users/amelvin/Documents/Arduino/deleteme/deleteme.ino:15:30: required from here
/Users/amelvin/Documents/Arduino/libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:127:13: error: 'class std::__cxx11::basic_string<char>' has no member named 'write'
_length += _writer.write(reinterpret_cast<const uint8_t *>(begin),