mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-11-07 01:51:37 +01:00
serializeXxx() sets std::string and String instead of appending
This commit is contained in:
@@ -13,8 +13,10 @@ class Writer<::String, void> {
|
||||
static const size_t bufferCapacity = ARDUINOJSON_STRING_BUFFER_SIZE;
|
||||
|
||||
public:
|
||||
explicit Writer(::String& str) : destination_(&str) {
|
||||
size_ = 0;
|
||||
explicit Writer(::String& str) : destination_(&str), size_(0) {
|
||||
// clear the string but don't use "" to avoid useless allocation
|
||||
// https://cpp4arduino.com/2018/11/21/eight-tips-to-use-the-string-class-efficiently.html
|
||||
str = static_cast<const char*>(0);
|
||||
}
|
||||
|
||||
~Writer() {
|
||||
|
||||
@@ -24,7 +24,9 @@ template <typename TDestination>
|
||||
class Writer<TDestination,
|
||||
typename enable_if<is_std_string<TDestination>::value>::type> {
|
||||
public:
|
||||
Writer(TDestination& str) : str_(&str) {}
|
||||
Writer(TDestination& str) : str_(&str) {
|
||||
str.clear();
|
||||
}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
str_->push_back(static_cast<char>(c));
|
||||
|
||||
Reference in New Issue
Block a user