Reorganized writer classes

This commit is contained in:
Benoit Blanchon
2019-10-31 19:27:23 +01:00
parent 6da6f921cd
commit 8721ac88b1
22 changed files with 235 additions and 201 deletions

View File

@@ -0,0 +1,36 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// MIT License
#pragma once
#include <WString.h>
namespace ARDUINOJSON_NAMESPACE {
template <>
class Writer< ::String, void> {
public:
explicit Writer(::String &str) : _str(&str) {}
size_t write(uint8_t c) {
_str->operator+=(static_cast<char>(c));
return 1;
}
size_t write(const uint8_t *s, size_t n) {
// CAUTION: Arduino String doesn't have append()
// and old version doesn't have size() either
_str->reserve(_str->length() + n);
while (n > 0) {
_str->operator+=(static_cast<char>(*s++));
n--;
}
return n;
}
private:
::String *_str;
};
} // namespace ARDUINOJSON_NAMESPACE