From 4f6253aa9fec99260b8bb7b9b2e9003f5259b600 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Sep 2018 10:02:07 +0200 Subject: Import arduinojson and ubjson. Only partially working at the moment --- .../lib/ArduinoJson/StringTraits/FlashString.hpp | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 include/lib/ArduinoJson/StringTraits/FlashString.hpp (limited to 'include/lib/ArduinoJson/StringTraits/FlashString.hpp') diff --git a/include/lib/ArduinoJson/StringTraits/FlashString.hpp b/include/lib/ArduinoJson/StringTraits/FlashString.hpp new file mode 100644 index 0000000..0701b9b --- /dev/null +++ b/include/lib/ArduinoJson/StringTraits/FlashString.hpp @@ -0,0 +1,61 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#if ARDUINOJSON_ENABLE_PROGMEM + +namespace ArduinoJson { +namespace Internals { +template <> +struct StringTraits { + class Reader { + const char* _ptr; + + public: + Reader(const __FlashStringHelper* ptr) + : _ptr(reinterpret_cast(ptr)) {} + + void move() { + _ptr++; + } + + char current() const { + return pgm_read_byte_near(_ptr); + } + + char next() const { + return pgm_read_byte_near(_ptr + 1); + } + }; + + static bool equals(const __FlashStringHelper* str, const char* expected) { + const char* actual = reinterpret_cast(str); + if (!actual || !expected) return actual == expected; + return strcmp_P(expected, actual) == 0; + } + + static bool is_null(const __FlashStringHelper* str) { + return !str; + } + + typedef const char* duplicate_t; + + template + static duplicate_t duplicate(const __FlashStringHelper* str, Buffer* buffer) { + if (!str) return NULL; + size_t size = strlen_P((const char*)str) + 1; + void* dup = buffer->alloc(size); + if (dup != NULL) memcpy_P(dup, (const char*)str, size); + return static_cast(dup); + } + + static const bool has_append = false; + static const bool has_equals = true; + static const bool should_duplicate = true; +}; +} // namespace Internals +} // namespace ArduinoJson + +#endif -- cgit v1.2.3