forked from bblanchon/ArduinoJson
Added DeserializationError::EmptyInput
This commit is contained in:
@ -20,6 +20,7 @@ class DeserializationError {
|
||||
public:
|
||||
enum Code {
|
||||
Ok,
|
||||
EmptyInput,
|
||||
IncompleteInput,
|
||||
InvalidInput,
|
||||
NoMemory,
|
||||
@ -77,22 +78,12 @@ class DeserializationError {
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
switch (_code) {
|
||||
case Ok:
|
||||
return "Ok";
|
||||
case TooDeep:
|
||||
return "TooDeep";
|
||||
case NoMemory:
|
||||
return "NoMemory";
|
||||
case InvalidInput:
|
||||
return "InvalidInput";
|
||||
case IncompleteInput:
|
||||
return "IncompleteInput";
|
||||
case NotSupported:
|
||||
return "NotSupported";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
static const char* messages[] = {
|
||||
"Ok", "EmptyInput", "IncompleteInput", "InvalidInput",
|
||||
"NoMemory", "NotSupported", "TooDeep"};
|
||||
ARDUINOJSON_ASSERT(static_cast<size_t>(_code) <
|
||||
sizeof(messages) / sizeof(messages[0]));
|
||||
return messages[_code];
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -23,6 +23,7 @@ class JsonDeserializer {
|
||||
JsonDeserializer(MemoryPool &pool, TReader reader,
|
||||
TStringStorage stringStorage)
|
||||
: _stringStorage(stringStorage),
|
||||
_foundSomething(false),
|
||||
_latch(reader),
|
||||
_pool(&pool),
|
||||
_error(DeserializationError::Ok) {}
|
||||
@ -34,7 +35,7 @@ class JsonDeserializer {
|
||||
|
||||
if (!_error && _latch.last() != 0 && !variant.isEnclosed()) {
|
||||
// We don't detect trailing characters earlier, so we need to check now
|
||||
_error = DeserializationError::InvalidInput;
|
||||
return DeserializationError::InvalidInput;
|
||||
}
|
||||
|
||||
return _error;
|
||||
@ -559,7 +560,8 @@ class JsonDeserializer {
|
||||
switch (current()) {
|
||||
// end of string
|
||||
case '\0':
|
||||
_error = DeserializationError::IncompleteInput;
|
||||
_error = _foundSomething ? DeserializationError::IncompleteInput
|
||||
: DeserializationError::EmptyInput;
|
||||
return false;
|
||||
|
||||
// spaces
|
||||
@ -619,12 +621,14 @@ class JsonDeserializer {
|
||||
#endif
|
||||
|
||||
default:
|
||||
_foundSomething = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TStringStorage _stringStorage;
|
||||
bool _foundSomething;
|
||||
Latch<TReader> _latch;
|
||||
MemoryPool *_pool;
|
||||
char _buffer[64]; // using a member instead of a local variable because it
|
||||
|
@ -21,22 +21,23 @@ class MsgPackDeserializer {
|
||||
: _pool(&pool),
|
||||
_reader(reader),
|
||||
_stringStorage(stringStorage),
|
||||
_error(DeserializationError::Ok) {}
|
||||
_error(DeserializationError::Ok),
|
||||
_foundSomething(false) {}
|
||||
|
||||
// TODO: add support for filter
|
||||
DeserializationError parse(VariantData &variant, AllowAllFilter,
|
||||
NestingLimit nestingLimit) {
|
||||
parseVariant(variant, nestingLimit);
|
||||
return _error;
|
||||
return _foundSomething ? _error : DeserializationError::EmptyInput;
|
||||
}
|
||||
|
||||
private:
|
||||
bool parseVariant(VariantData &variant, NestingLimit nestingLimit) {
|
||||
uint8_t code;
|
||||
if (!readByte(code)) {
|
||||
_error = DeserializationError::IncompleteInput;
|
||||
if (!readByte(code))
|
||||
return false;
|
||||
}
|
||||
|
||||
_foundSomething = true;
|
||||
|
||||
if ((code & 0x80) == 0) {
|
||||
variant.setUnsignedInteger(code);
|
||||
@ -345,6 +346,7 @@ class MsgPackDeserializer {
|
||||
TReader _reader;
|
||||
TStringStorage _stringStorage;
|
||||
DeserializationError _error;
|
||||
bool _foundSomething;
|
||||
};
|
||||
|
||||
template <typename TInput>
|
||||
|
Reference in New Issue
Block a user