summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp')
-rw-r--r--include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp b/include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp
new file mode 100644
index 0000000..e08ba4d
--- /dev/null
+++ b/include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp
@@ -0,0 +1,32 @@
+// ArduinoJson - https://arduinojson.org
+// Copyright Benoit Blanchon 2014-2021
+// MIT License
+
+#pragma once
+
+#include <ostream>
+
+namespace ARDUINOJSON_NAMESPACE {
+
+template <typename TDestination>
+class Writer<
+ TDestination,
+ typename enable_if<is_base_of<std::ostream, TDestination>::value>::type> {
+ public:
+ explicit Writer(std::ostream& os) : _os(&os) {}
+
+ size_t write(uint8_t c) {
+ _os->put(static_cast<char>(c));
+ return 1;
+ }
+
+ size_t write(const uint8_t* s, size_t n) {
+ _os->write(reinterpret_cast<const char*>(s),
+ static_cast<std::streamsize>(n));
+ return n;
+ }
+
+ private:
+ std::ostream* _os;
+};
+} // namespace ARDUINOJSON_NAMESPACE