Print.h 690 B

123456789101112131415161718192021222324252627282930313233
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #pragma once
  5. #include <stdint.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. class Print {
  9. public:
  10. virtual ~Print() {}
  11. virtual size_t write(uint8_t) = 0;
  12. virtual size_t write(const uint8_t *buffer, size_t size) = 0;
  13. size_t write(const char *str) {
  14. if (!str)
  15. return 0;
  16. return write(reinterpret_cast<const uint8_t *>(str), strlen(str));
  17. }
  18. size_t write(const char *buffer, size_t size) {
  19. return write(reinterpret_cast<const uint8_t *>(buffer), size);
  20. }
  21. };
  22. class Printable {
  23. public:
  24. virtual ~Printable() {}
  25. virtual size_t printTo(Print &p) const = 0;
  26. };