Printers.cpp 822 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include "Printers.hpp"
  7. #include <ArduinoJson/JsonArray.hpp>
  8. class StreamPrintAdapter : public Print {
  9. public:
  10. explicit StreamPrintAdapter(std::ostream& os) : _os(os) {}
  11. virtual size_t write(uint8_t c) {
  12. _os << static_cast<char>(c);
  13. return 1;
  14. }
  15. private:
  16. std::ostream& _os;
  17. };
  18. std::ostream& ArduinoJson::operator<<(std::ostream& os,
  19. const ArduinoJson::JsonVariant& v) {
  20. StreamPrintAdapter adapter(os);
  21. v.printTo(adapter);
  22. return os;
  23. }
  24. std::ostream& ArduinoJson::operator<<(std::ostream& os,
  25. const ArduinoJson::JsonArray& v) {
  26. StreamPrintAdapter adapter(os);
  27. v.printTo(adapter);
  28. return os;
  29. }