Added DeserializationError::f_str() (issue #846)

This commit is contained in:
Benoit Blanchon
2020-09-14 09:30:58 +02:00
parent c907ca6e5d
commit c4ec2ba88f
7 changed files with 46 additions and 22 deletions

View File

@ -86,6 +86,23 @@ class DeserializationError {
return messages[_code];
}
#if ARDUINOJSON_ENABLE_PROGMEM
const __FlashStringHelper* f_str() const {
static const char s0[] PROGMEM = "Ok";
static const char s1[] PROGMEM = "EmptyInput";
static const char s2[] PROGMEM = "IncompleteInput";
static const char s3[] PROGMEM = "InvalidInput";
static const char s4[] PROGMEM = "NoMemory";
static const char s5[] PROGMEM = "NotSupported";
static const char s6[] PROGMEM = "TooDeep";
static const char* const messages[] PROGMEM = {s0, s1, s2, s3, s4, s5, s6};
ARDUINOJSON_ASSERT(static_cast<size_t>(_code) <
sizeof(messages) / sizeof(messages[0]));
return reinterpret_cast<const __FlashStringHelper*>(
pgm_read_ptr(messages + _code));
}
#endif
private:
Code _code;
};