Browse Source

Fixed "no matching function for call to write(uint8_t)" (closes #972)

Benoit Blanchon 6 years ago
parent
commit
12f9aac4ea
3 changed files with 31 additions and 14 deletions
  1. 1 0
      CHANGELOG.md
  2. 14 4
      src/ArduinoJson/Configuration.hpp
  3. 16 10
      src/ArduinoJson/Serialization/serialize.hpp

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@ HEAD
 
 * Fixed error "attributes are not allowed on a function-definition"
 * Fixed `deserializeJson()` not being picky enough (issue #969)
+* Fixed error "no matching function for call to write(uint8_t)" (issue #972)
 
 v6.10.0 (2019-03-22)
 -------

+ 14 - 4
src/ArduinoJson/Configuration.hpp

@@ -88,28 +88,38 @@
 
 #ifdef ARDUINO
 
-// Enable support for Arduino String
+// Enable support for Arduino's String class
 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
 #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
 #endif
 
-// Enable support for Arduino Stream
+// Enable support for Arduino's Stream class
 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
 #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1
 #endif
 
+// Enable support for Arduino's Print class
+#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
+#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1
+#endif
+
 #else  // ARDUINO
 
-// Disable support for Arduino String
+// Enable support for Arduino's String class
 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
 #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
 #endif
 
-// Disable support for Arduino Stream
+// Enable support for Arduino's Stream class
 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
 #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0
 #endif
 
+// Enable support for Arduino's Print class
+#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
+#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0
+#endif
+
 #endif  // ARDUINO
 
 #ifndef ARDUINOJSON_ENABLE_PROGMEM

+ 16 - 10
src/ArduinoJson/Serialization/serialize.hpp

@@ -14,32 +14,38 @@
 namespace ARDUINOJSON_NAMESPACE {
 
 template <template <typename> class TSerializer, typename TSource,
-          typename TPrint>
-typename enable_if<!IsWriteableString<TPrint>::value, size_t>::type serialize(
-    const TSource &source, TPrint &destination) {
-  TSerializer<TPrint> serializer(destination);
+          typename TDestination>
+size_t doSerialize(const TSource &source, TDestination &destination) {
+  TSerializer<TDestination> serializer(destination);
   source.accept(serializer);
   return serializer.bytesWritten();
 }
 
 #if ARDUINOJSON_ENABLE_STD_STREAM
 template <template <typename> class TSerializer, typename TSource>
-size_t serialize(const TSource &source, std::ostream &os) {
-  StreamWriter writer(os);
-  return serialize<TSerializer>(source, writer);
+size_t serialize(const TSource &source, std::ostream &destination) {
+  StreamWriter writer(destination);
+  return doSerialize<TSerializer>(source, writer);
+}
+#endif
+
+#if ARDUINOJSON_ENABLE_ARDUINO_PRINT
+template <template <typename> class TSerializer, typename TSource>
+size_t serialize(const TSource &source, Print &destination) {
+  return doSerialize<TSerializer>(source, destination);
 }
 #endif
 
 template <template <typename> class TSerializer, typename TSource>
 size_t serialize(const TSource &source, char *buffer, size_t bufferSize) {
   StaticStringWriter writer(buffer, bufferSize);
-  return serialize<TSerializer>(source, writer);
+  return doSerialize<TSerializer>(source, writer);
 }
 
 template <template <typename> class TSerializer, typename TSource, size_t N>
 size_t serialize(const TSource &source, char (&buffer)[N]) {
   StaticStringWriter writer(buffer, N);
-  return serialize<TSerializer>(source, writer);
+  return doSerialize<TSerializer>(source, writer);
 }
 
 template <template <typename> class TSerializer, typename TSource,
@@ -47,7 +53,7 @@ template <template <typename> class TSerializer, typename TSource,
 typename enable_if<IsWriteableString<TString>::value, size_t>::type serialize(
     const TSource &source, TString &str) {
   DynamicStringWriter<TString> writer(str);
-  return serialize<TSerializer>(source, writer);
+  return doSerialize<TSerializer>(source, writer);
 }
 
 }  // namespace ARDUINOJSON_NAMESPACE