mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
remove TODO
This commit is contained in:
@@ -16,24 +16,23 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
template <typename TReader, typename TStringStorage>
|
||||
class MsgPackDeserializer {
|
||||
public:
|
||||
MsgPackDeserializer(MemoryPool &pool, TReader reader,
|
||||
TStringStorage stringStorage)
|
||||
: _pool(&pool),
|
||||
_reader(reader),
|
||||
_stringStorage(stringStorage),
|
||||
_error(DeserializationError::Ok),
|
||||
_foundSomething(false) {}
|
||||
MsgPackDeserializer(MemoryPool & pool, TReader reader, TStringStorage stringStorage)
|
||||
: _pool(&pool)
|
||||
, _reader(reader)
|
||||
, _stringStorage(stringStorage)
|
||||
, _error(DeserializationError::Ok)
|
||||
, _foundSomething(false) {
|
||||
}
|
||||
|
||||
template <typename TFilter>
|
||||
DeserializationError parse(VariantData &variant, TFilter filter,
|
||||
NestingLimit nestingLimit) {
|
||||
DeserializationError parse(VariantData & variant, TFilter filter, NestingLimit nestingLimit) {
|
||||
parseVariant(&variant, filter, nestingLimit);
|
||||
return _foundSomething ? _error : DeserializationError::EmptyInput;
|
||||
}
|
||||
|
||||
private:
|
||||
// Prevent VS warning "assignment operator could not be generated"
|
||||
MsgPackDeserializer &operator=(const MsgPackDeserializer &);
|
||||
MsgPackDeserializer & operator=(const MsgPackDeserializer &);
|
||||
|
||||
bool invalidInput() {
|
||||
_error = DeserializationError::InvalidInput;
|
||||
@@ -41,9 +40,8 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename TFilter>
|
||||
bool parseVariant(VariantData *variant, TFilter filter,
|
||||
NestingLimit nestingLimit) {
|
||||
uint8_t code = 0; // TODO: why do we need to initialize this variable?
|
||||
bool parseVariant(VariantData * variant, TFilter filter, NestingLimit nestingLimit) {
|
||||
uint8_t code = 0;
|
||||
if (!readByte(code))
|
||||
return false;
|
||||
|
||||
@@ -222,7 +220,7 @@ class MsgPackDeserializer {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readByte(uint8_t &value) {
|
||||
bool readByte(uint8_t & value) {
|
||||
int c = _reader.read();
|
||||
if (c < 0) {
|
||||
_error = DeserializationError::IncompleteInput;
|
||||
@@ -232,7 +230,7 @@ class MsgPackDeserializer {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readBytes(uint8_t *p, size_t n) {
|
||||
bool readBytes(uint8_t * p, size_t n) {
|
||||
if (_reader.readBytes(reinterpret_cast<char *>(p), n) == n)
|
||||
return true;
|
||||
_error = DeserializationError::IncompleteInput;
|
||||
@@ -240,7 +238,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool readBytes(T &value) {
|
||||
bool readBytes(T & value) {
|
||||
return readBytes(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
@@ -255,7 +253,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool readInteger(T &value) {
|
||||
bool readInteger(T & value) {
|
||||
if (!readBytes(value))
|
||||
return false;
|
||||
fixEndianess(value);
|
||||
@@ -263,7 +261,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool readInteger(VariantData *variant) {
|
||||
bool readInteger(VariantData * variant) {
|
||||
T value;
|
||||
if (!readInteger(value))
|
||||
return false;
|
||||
@@ -272,8 +270,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<sizeof(T) == 4, bool>::type readFloat(
|
||||
VariantData *variant) {
|
||||
typename enable_if<sizeof(T) == 4, bool>::type readFloat(VariantData * variant) {
|
||||
T value;
|
||||
if (!readBytes(value))
|
||||
return false;
|
||||
@@ -283,8 +280,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<sizeof(T) == 8, bool>::type readDouble(
|
||||
VariantData *variant) {
|
||||
typename enable_if<sizeof(T) == 8, bool>::type readDouble(VariantData * variant) {
|
||||
T value;
|
||||
if (!readBytes(value))
|
||||
return false;
|
||||
@@ -294,11 +290,10 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<sizeof(T) == 4, bool>::type readDouble(
|
||||
VariantData *variant) {
|
||||
typename enable_if<sizeof(T) == 4, bool>::type readDouble(VariantData * variant) {
|
||||
uint8_t i[8]; // input is 8 bytes
|
||||
T value; // output is 4 bytes
|
||||
uint8_t *o = reinterpret_cast<uint8_t *>(&value);
|
||||
uint8_t * o = reinterpret_cast<uint8_t *>(&value);
|
||||
if (!readBytes(i, 8))
|
||||
return false;
|
||||
doubleToFloat(i, o);
|
||||
@@ -308,7 +303,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool readString(VariantData *variant) {
|
||||
bool readString(VariantData * variant) {
|
||||
T size;
|
||||
if (!readInteger(size))
|
||||
return false;
|
||||
@@ -331,11 +326,10 @@ class MsgPackDeserializer {
|
||||
return skipBytes(size);
|
||||
}
|
||||
|
||||
bool readString(VariantData *variant, size_t n) {
|
||||
bool readString(VariantData * variant, size_t n) {
|
||||
if (!readString(n))
|
||||
return false;
|
||||
variant->setStringPointer(_stringStorage.save(),
|
||||
typename TStringStorage::storage_policy());
|
||||
variant->setStringPointer(_stringStorage.save(), typename TStringStorage::storage_policy());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -357,8 +351,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename TSize, typename TFilter>
|
||||
bool readArray(VariantData *variant, TFilter filter,
|
||||
NestingLimit nestingLimit) {
|
||||
bool readArray(VariantData * variant, TFilter filter, NestingLimit nestingLimit) {
|
||||
TSize size;
|
||||
if (!readInteger(size))
|
||||
return false;
|
||||
@@ -366,8 +359,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename TFilter>
|
||||
bool readArray(VariantData *variant, size_t n, TFilter filter,
|
||||
NestingLimit nestingLimit) {
|
||||
bool readArray(VariantData * variant, size_t n, TFilter filter, NestingLimit nestingLimit) {
|
||||
if (nestingLimit.reached()) {
|
||||
_error = DeserializationError::TooDeep;
|
||||
return false;
|
||||
@@ -375,12 +367,12 @@ class MsgPackDeserializer {
|
||||
|
||||
bool allowArray = filter.allowArray();
|
||||
|
||||
CollectionData *array = allowArray ? &variant->toArray() : 0;
|
||||
CollectionData * array = allowArray ? &variant->toArray() : 0;
|
||||
|
||||
TFilter memberFilter = filter[0U];
|
||||
|
||||
for (; n; --n) {
|
||||
VariantData *value;
|
||||
VariantData * value;
|
||||
|
||||
if (memberFilter.allow()) {
|
||||
value = array->addElement(_pool);
|
||||
@@ -400,8 +392,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename TSize, typename TFilter>
|
||||
bool readObject(VariantData *variant, TFilter filter,
|
||||
NestingLimit nestingLimit) {
|
||||
bool readObject(VariantData * variant, TFilter filter, NestingLimit nestingLimit) {
|
||||
TSize size;
|
||||
if (!readInteger(size))
|
||||
return false;
|
||||
@@ -409,29 +400,28 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename TFilter>
|
||||
bool readObject(VariantData *variant, size_t n, TFilter filter,
|
||||
NestingLimit nestingLimit) {
|
||||
bool readObject(VariantData * variant, size_t n, TFilter filter, NestingLimit nestingLimit) {
|
||||
if (nestingLimit.reached()) {
|
||||
_error = DeserializationError::TooDeep;
|
||||
return false;
|
||||
}
|
||||
|
||||
CollectionData *object = filter.allowObject() ? &variant->toObject() : 0;
|
||||
CollectionData * object = filter.allowObject() ? &variant->toObject() : 0;
|
||||
|
||||
for (; n; --n) {
|
||||
if (!readKey())
|
||||
return false;
|
||||
|
||||
const char *key = _stringStorage.c_str();
|
||||
const char * key = _stringStorage.c_str();
|
||||
TFilter memberFilter = filter[key];
|
||||
VariantData *member;
|
||||
VariantData * member;
|
||||
|
||||
if (memberFilter.allow()) {
|
||||
// Save key in memory pool.
|
||||
// This MUST be done before adding the slot.
|
||||
key = _stringStorage.save();
|
||||
|
||||
VariantSlot *slot = object->addSlot(_pool);
|
||||
VariantSlot * slot = object->addSlot(_pool);
|
||||
if (!slot) {
|
||||
_error = DeserializationError::NoMemory;
|
||||
return false;
|
||||
@@ -482,7 +472,7 @@ class MsgPackDeserializer {
|
||||
return skipBytes(size + 1);
|
||||
}
|
||||
|
||||
MemoryPool *_pool;
|
||||
MemoryPool * _pool;
|
||||
TReader _reader;
|
||||
TStringStorage _stringStorage;
|
||||
DeserializationError _error;
|
||||
@@ -494,24 +484,17 @@ class MsgPackDeserializer {
|
||||
//
|
||||
// ... = NestingLimit
|
||||
template <typename TString>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, const TString &input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & input, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
template <typename TString>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, const TString &input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & input, Filter filter, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
template <typename TString>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, const TString &input,
|
||||
NestingLimit nestingLimit,
|
||||
Filter filter) {
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & input, NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
@@ -520,24 +503,17 @@ DeserializationError deserializeMsgPack(JsonDocument &doc, const TString &input,
|
||||
//
|
||||
// ... = NestingLimit
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TStream &input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TStream &input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, Filter filter, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, TStream &input,
|
||||
NestingLimit nestingLimit,
|
||||
Filter filter) {
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
@@ -546,24 +522,17 @@ DeserializationError deserializeMsgPack(JsonDocument &doc, TStream &input,
|
||||
//
|
||||
// ... = NestingLimit
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TChar *input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TChar *input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, Filter filter, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, TChar *input,
|
||||
NestingLimit nestingLimit,
|
||||
Filter filter) {
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
@@ -572,28 +541,18 @@ DeserializationError deserializeMsgPack(JsonDocument &doc, TChar *input,
|
||||
//
|
||||
// ... = NestingLimit
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TChar *input, size_t inputSize,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
AllowAllFilter());
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, size_t inputSize, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit, AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TChar *input, size_t inputSize, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
filter);
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, size_t inputSize, Filter filter, NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, TChar *input,
|
||||
size_t inputSize,
|
||||
NestingLimit nestingLimit,
|
||||
Filter filter) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
filter);
|
||||
DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, size_t inputSize, NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit, filter);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user