Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers StdStreamWriter.hpp Source File

StdStreamWriter.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ostream>
00008 
00009 namespace ARDUINOJSON_NAMESPACE {
00010 
00011 template <typename TDestination>
00012 class Writer<
00013     TDestination,
00014     typename enable_if<is_base_of<std::ostream, TDestination>::value>::type> {
00015  public:
00016   explicit Writer(std::ostream& os) : _os(&os) {}
00017 
00018   size_t write(uint8_t c) {
00019     _os->put(static_cast<char>(c));
00020     return 1;
00021   }
00022 
00023   size_t write(const uint8_t* s, size_t n) {
00024     _os->write(reinterpret_cast<const char*>(s),
00025                static_cast<std::streamsize>(n));
00026     return n;
00027   }
00028 
00029  private:
00030   std::ostream* _os;
00031 };
00032 }  // namespace ARDUINOJSON_NAMESPACE