|
|
@@ -4,6 +4,7 @@
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
+#include <ArduinoJson/Configuration.hpp>
|
|
|
#include <ArduinoJson/Serialization/DynamicStringWriter.hpp>
|
|
|
#include <ArduinoJson/Serialization/StaticStringWriter.hpp>
|
|
|
|
|
|
@@ -11,30 +12,26 @@
|
|
|
#include <ArduinoJson/Serialization/StreamWriter.hpp>
|
|
|
#endif
|
|
|
|
|
|
+#if ARDUINOJSON_ENABLE_ARDUINO_PRINT
|
|
|
+#include <ArduinoJson/Serialization/PrintWriter.hpp>
|
|
|
+#endif
|
|
|
+
|
|
|
namespace ARDUINOJSON_NAMESPACE {
|
|
|
|
|
|
template <template <typename> class TSerializer, typename TSource,
|
|
|
- typename TDestination>
|
|
|
-size_t doSerialize(const TSource &source, TDestination &destination) {
|
|
|
- TSerializer<TDestination> serializer(destination);
|
|
|
+ typename TWriter>
|
|
|
+size_t doSerialize(const TSource &source, TWriter &writer) {
|
|
|
+ TSerializer<TWriter> serializer(writer);
|
|
|
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 &destination) {
|
|
|
- StreamWriter writer(destination);
|
|
|
+template <template <typename> class TSerializer, typename TSource,
|
|
|
+ typename TDestination>
|
|
|
+size_t serialize(const TSource &source, TDestination &destination) {
|
|
|
+ typename WriterSelector<TDestination>::writer_type 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) {
|
|
|
@@ -48,12 +45,4 @@ size_t serialize(const TSource &source, char (&buffer)[N]) {
|
|
|
return doSerialize<TSerializer>(source, writer);
|
|
|
}
|
|
|
|
|
|
-template <template <typename> class TSerializer, typename TSource,
|
|
|
- typename TString>
|
|
|
-typename enable_if<IsWriteableString<TString>::value, size_t>::type serialize(
|
|
|
- const TSource &source, TString &str) {
|
|
|
- DynamicStringWriter<TString> writer(str);
|
|
|
- return doSerialize<TSerializer>(source, writer);
|
|
|
-}
|
|
|
-
|
|
|
} // namespace ARDUINOJSON_NAMESPACE
|