forked from bblanchon/ArduinoJson
Added deserializeMsgPack() (issue #358)
This commit is contained in:
1 parent
923d3e8a84
commit
cb723840d9
58 files changed
+1311
-89
No files matched your search
+4
-2
@@ -7,13 +7,15 @@
|
||||
#include "ArduinoJson/DynamicJsonArray.hpp"
|
||||
#include "ArduinoJson/DynamicJsonObject.hpp"
|
||||
#include "ArduinoJson/DynamicJsonVariant.hpp"
|
||||
#include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp"
|
||||
#include "ArduinoJson/StaticJsonArray.hpp"
|
||||
#include "ArduinoJson/StaticJsonObject.hpp"
|
||||
#include "ArduinoJson/StaticJsonVariant.hpp"
|
||||
#include "ArduinoJson/deserializeJson.hpp"
|
||||
#include "ArduinoJson/deserializeMsgPack.hpp"
|
||||
|
||||
#include "ArduinoJson/Deserialization/JsonParserImpl.hpp"
|
||||
#include "ArduinoJson/Json/Deserialization/JsonParserImpl.hpp"
|
||||
#include "ArduinoJson/Json/Serialization/JsonSerializerImpl.hpp"
|
||||
#include "ArduinoJson/JsonArrayImpl.hpp"
|
||||
#include "ArduinoJson/JsonObjectImpl.hpp"
|
||||
#include "ArduinoJson/JsonVariantImpl.hpp"
|
||||
#include "ArduinoJson/Serialization/JsonSerializerImpl.hpp"
|
||||
@@ -144,3 +144,13 @@
|
||||
#if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64
|
||||
#error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together
|
||||
#endif
|
||||
|
||||
#ifndef ARDUINOJSON_LITTLE_ENDIAN
|
||||
#if defined(_MSC_VER) || \
|
||||
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
|
||||
(defined(__LITTLE_ENDIAN__))
|
||||
#define ARDUINOJSON_LITTLE_ENDIAN 1
|
||||
#else
|
||||
#define ARDUINOJSON_LITTLE_ENDIAN 0
|
||||
#endif
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "../JsonVariant.hpp"
|
||||
#include "../Memory/JsonBuffer.hpp"
|
||||
#include "../StringTraits/StringTraits.hpp"
|
||||
#include "../Strings/StringTraits.hpp"
|
||||
#include "../TypeTraits/EnableIf.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
File renamed without changes.
+5
-5
@@ -4,11 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JsonError.hpp"
|
||||
#include "../JsonVariant.hpp"
|
||||
#include "../Memory/JsonBuffer.hpp"
|
||||
#include "../TypeTraits/IsConst.hpp"
|
||||
#include "StringWriter.hpp"
|
||||
#include "../../JsonError.hpp"
|
||||
#include "../../JsonVariant.hpp"
|
||||
#include "../../Memory/JsonBuffer.hpp"
|
||||
#include "../../Strings/StringWriter.hpp"
|
||||
#include "../../TypeTraits/IsConst.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Data/Encoding.hpp"
|
||||
#include "../Encoding.hpp"
|
||||
#include "Comments.hpp"
|
||||
#include "JsonParser.hpp"
|
||||
|
||||
File renamed without changes.
+5
-5
@@ -4,9 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Configuration.hpp"
|
||||
#include "../Polyfills/math.hpp"
|
||||
#include "../TypeTraits/FloatTraits.hpp"
|
||||
#include "../../Configuration.hpp"
|
||||
#include "../../Polyfills/math.hpp"
|
||||
#include "../../TypeTraits/FloatTraits.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@@ -85,5 +85,5 @@ struct FloatParts {
|
||||
return powersOf10;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
File renamed without changes.
+7
-7
@@ -4,15 +4,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DummyPrint.hpp"
|
||||
#include "DynamicStringBuilder.hpp"
|
||||
#include "IndentedPrint.hpp"
|
||||
#include "JsonWriter.hpp"
|
||||
#include "Prettyfier.hpp"
|
||||
#include "StaticStringBuilder.hpp"
|
||||
#include "../../Print/DummyPrint.hpp"
|
||||
#include "../../Print/DynamicStringBuilder.hpp"
|
||||
#include "../../Print/StaticStringBuilder.hpp"
|
||||
#include "./IndentedPrint.hpp"
|
||||
#include "./JsonWriter.hpp"
|
||||
#include "./Prettyfier.hpp"
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STREAM
|
||||
#include "StreamPrintAdapter.hpp"
|
||||
#include "../../Print/StreamPrintAdapter.hpp"
|
||||
#endif
|
||||
|
||||
namespace ArduinoJson {
|
||||
+5
-5
@@ -4,11 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JsonArray.hpp"
|
||||
#include "../JsonArraySubscript.hpp"
|
||||
#include "../JsonObject.hpp"
|
||||
#include "../JsonObjectSubscript.hpp"
|
||||
#include "../JsonVariant.hpp"
|
||||
#include "../../JsonArray.hpp"
|
||||
#include "../../JsonArraySubscript.hpp"
|
||||
#include "../../JsonObject.hpp"
|
||||
#include "../../JsonObjectSubscript.hpp"
|
||||
#include "../../JsonVariant.hpp"
|
||||
#include "JsonSerializer.hpp"
|
||||
|
||||
template <typename Writer>
|
||||
+4
-4
@@ -5,10 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../Data/Encoding.hpp"
|
||||
#include "../Data/JsonInteger.hpp"
|
||||
#include "../Polyfills/attributes.hpp"
|
||||
#include "../Serialization/FloatParts.hpp"
|
||||
#include "../../Data/JsonInteger.hpp"
|
||||
#include "../../Polyfills/attributes.hpp"
|
||||
#include "../Encoding.hpp"
|
||||
#include "./FloatParts.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
File renamed without changes.
@@ -9,7 +9,7 @@
|
||||
#include "Data/ValueSaver.hpp"
|
||||
#include "JsonVariant.hpp"
|
||||
#include "Memory/JsonBufferAllocated.hpp"
|
||||
#include "StringTraits/StringTraits.hpp"
|
||||
#include "Strings/StringTraits.hpp"
|
||||
#include "TypeTraits/EnableIf.hpp"
|
||||
#include "TypeTraits/IsArray.hpp"
|
||||
#include "TypeTraits/IsFloatingPoint.hpp"
|
||||
|
||||
@@ -42,15 +42,7 @@ class JsonError {
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
return to_string(_code);
|
||||
}
|
||||
|
||||
friend const char* to_string(const JsonError err) {
|
||||
return to_string(err._code);
|
||||
}
|
||||
|
||||
friend const char* to_string(JsonError::Code code) {
|
||||
switch (code) {
|
||||
switch (_code) {
|
||||
case Ok:
|
||||
return "Ok";
|
||||
case OpeningBraceExpected:
|
||||
@@ -78,12 +70,7 @@ class JsonError {
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STREAM
|
||||
inline std::ostream& operator<<(std::ostream& s, const JsonError& e) {
|
||||
s << to_string(e);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& s, JsonError::Code e) {
|
||||
s << to_string(e);
|
||||
s << e.c_str();
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "Data/ValueSaver.hpp"
|
||||
#include "JsonPair.hpp"
|
||||
#include "Memory/JsonBufferAllocated.hpp"
|
||||
#include "StringTraits/StringTraits.hpp"
|
||||
#include "Strings/StringTraits.hpp"
|
||||
#include "TypeTraits/EnableIf.hpp"
|
||||
#include "TypeTraits/IsArray.hpp"
|
||||
#include "TypeTraits/IsFloatingPoint.hpp"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "StringTraits/StringTraits.hpp"
|
||||
#include "Strings/StringTraits.hpp"
|
||||
#include "TypeTraits/EnableIf.hpp"
|
||||
#include "TypeTraits/IsVariant.hpp"
|
||||
|
||||
@@ -134,5 +134,5 @@ class JsonVariantComparisons {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -8,10 +8,10 @@
|
||||
#include "JsonArray.hpp"
|
||||
#include "JsonObject.hpp"
|
||||
#include "JsonVariant.hpp"
|
||||
#include "Polyfills/isFloat.hpp"
|
||||
#include "Polyfills/isInteger.hpp"
|
||||
#include "Polyfills/parseFloat.hpp"
|
||||
#include "Polyfills/parseInteger.hpp"
|
||||
#include "Text/isFloat.hpp"
|
||||
#include "Text/isInteger.hpp"
|
||||
#include "Text/parseFloat.hpp"
|
||||
#include "Text/parseInteger.hpp"
|
||||
|
||||
#include <string.h> // for strcmp
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "Data/JsonVariantAs.hpp"
|
||||
#include "Polyfills/attributes.hpp"
|
||||
#include "StringTraits/StringTraits.hpp"
|
||||
#include "Strings/StringTraits.hpp"
|
||||
#include "TypeTraits/EnableIf.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
@@ -82,5 +82,5 @@ class JsonVariantSubscripts {
|
||||
return static_cast<const TImpl *>(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -0,0 +1,328 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JsonVariant.hpp"
|
||||
#include "../Memory/JsonBuffer.hpp"
|
||||
#include "../Strings/StringWriter.hpp"
|
||||
#include "../TypeTraits/IsConst.hpp"
|
||||
#include "./MsgPackError.hpp"
|
||||
#include "./endianess.hpp"
|
||||
#include "./ieee754.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
// Parse JSON string to create JsonArrays and JsonObjects
|
||||
// This internal class is not indended to be used directly.
|
||||
// Instead, use JsonBuffer.parseArray() or .parseObject()
|
||||
template <typename TReader, typename TWriter>
|
||||
class MsgPackDeserializer {
|
||||
public:
|
||||
MsgPackDeserializer(JsonBuffer *buffer, TReader reader, TWriter writer,
|
||||
uint8_t nestingLimit)
|
||||
: _buffer(buffer),
|
||||
_reader(reader),
|
||||
_writer(writer),
|
||||
_nestingLimit(nestingLimit) {}
|
||||
|
||||
MsgPackError parse(JsonArray &array) {
|
||||
uint8_t c = readOne();
|
||||
size_t n;
|
||||
|
||||
if ((c & 0xF0) == 0x90) {
|
||||
n = c & 0x0F;
|
||||
} else if (c == 0xdc) {
|
||||
n = readInteger<uint16_t>();
|
||||
} else if (c == 0xdd) {
|
||||
n = readInteger<uint32_t>();
|
||||
} else {
|
||||
return MsgPackError::NotAnArray;
|
||||
}
|
||||
|
||||
return readArray(array, n);
|
||||
}
|
||||
|
||||
MsgPackError parse(JsonObject &object) {
|
||||
uint8_t c = readOne();
|
||||
size_t n;
|
||||
|
||||
if ((c & 0xf0) == 0x80) {
|
||||
n = c & 0x0f;
|
||||
} else if (c == 0xde) {
|
||||
n = readInteger<uint16_t>();
|
||||
} else if (c == 0xdf) {
|
||||
n = readInteger<uint32_t>();
|
||||
} else {
|
||||
return MsgPackError::NotAnObject;
|
||||
}
|
||||
|
||||
return readObject(object, n);
|
||||
}
|
||||
|
||||
MsgPackError parse(JsonVariant &variant) {
|
||||
uint8_t c = readOne();
|
||||
|
||||
if ((c & 0x80) == 0) {
|
||||
variant = c;
|
||||
return MsgPackError::Ok;
|
||||
}
|
||||
|
||||
if ((c & 0xe0) == 0xe0) {
|
||||
variant = static_cast<int8_t>(c);
|
||||
return MsgPackError::Ok;
|
||||
}
|
||||
|
||||
if ((c & 0xe0) == 0xa0) {
|
||||
return readString(variant, c & 0x1f);
|
||||
}
|
||||
|
||||
if ((c & 0xf0) == 0x90) return readArray(variant, c & 0x0F);
|
||||
|
||||
if ((c & 0xf0) == 0x80) return readObject(variant, c & 0x0F);
|
||||
|
||||
switch (c) {
|
||||
case 0xc0:
|
||||
variant = static_cast<char *>(0);
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xc2:
|
||||
variant = false;
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xc3:
|
||||
variant = true;
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xcc:
|
||||
variant = readInteger<uint8_t>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xcd:
|
||||
variant = readInteger<uint16_t>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xce:
|
||||
variant = readInteger<uint32_t>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xcf:
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
variant = readInteger<uint64_t>();
|
||||
#else
|
||||
readInteger<uint32_t>();
|
||||
variant = readInteger<uint32_t>();
|
||||
#endif
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xd0:
|
||||
variant = readInteger<int8_t>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xd1:
|
||||
variant = readInteger<int16_t>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xd2:
|
||||
variant = readInteger<int32_t>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xd3:
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
variant = readInteger<int64_t>();
|
||||
#else
|
||||
readInteger<int32_t>();
|
||||
variant = readInteger<int32_t>();
|
||||
#endif
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xca:
|
||||
variant = readFloat<float>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xcb:
|
||||
variant = readDouble<double>();
|
||||
return MsgPackError::Ok;
|
||||
|
||||
case 0xd9: {
|
||||
uint8_t n = readInteger<uint8_t>();
|
||||
return readString(variant, n);
|
||||
}
|
||||
|
||||
case 0xda: {
|
||||
uint16_t n = readInteger<uint16_t>();
|
||||
return readString(variant, n);
|
||||
}
|
||||
|
||||
case 0xdb: {
|
||||
uint32_t n = readInteger<uint32_t>();
|
||||
return readString(variant, n);
|
||||
}
|
||||
|
||||
case 0xdc:
|
||||
return readArray(variant, readInteger<uint16_t>());
|
||||
|
||||
case 0xdd:
|
||||
return readArray(variant, readInteger<uint32_t>());
|
||||
|
||||
case 0xde:
|
||||
return readObject(variant, readInteger<uint16_t>());
|
||||
|
||||
case 0xdf:
|
||||
return readObject(variant, readInteger<uint32_t>());
|
||||
|
||||
default:
|
||||
return MsgPackError::NotSupported;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Prevent VS warning "assignment operator could not be generated"
|
||||
MsgPackDeserializer &operator=(const MsgPackDeserializer &);
|
||||
|
||||
uint8_t readOne() {
|
||||
char c = _reader.current();
|
||||
_reader.move();
|
||||
return static_cast<uint8_t>(c);
|
||||
}
|
||||
|
||||
void read(uint8_t *p, size_t n) {
|
||||
for (size_t i = 0; i < n; i++) p[i] = readOne();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void read(T &value) {
|
||||
read(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T readInteger() {
|
||||
T value;
|
||||
read(value);
|
||||
fixEndianess(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename EnableIf<sizeof(T) == 4, T>::type readFloat() {
|
||||
T value;
|
||||
read(value);
|
||||
fixEndianess(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename EnableIf<sizeof(T) == 8, T>::type readDouble() {
|
||||
T value;
|
||||
read(value);
|
||||
fixEndianess(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename EnableIf<sizeof(T) == 4, T>::type readDouble() {
|
||||
uint8_t i[8]; // input is 8 bytes
|
||||
T value; // output is 4 bytes
|
||||
uint8_t *o = reinterpret_cast<uint8_t *>(&value);
|
||||
read(i, 8);
|
||||
doubleToFloat(i, o);
|
||||
fixEndianess(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
MsgPackError readString(JsonVariant &variant, size_t n) {
|
||||
typename RemoveReference<TWriter>::type::String str = _writer.startString();
|
||||
for (; n; --n) str.append(static_cast<char>(readOne()));
|
||||
const char *s = str.c_str();
|
||||
if (s == NULL) return MsgPackError::NoMemory;
|
||||
variant = s;
|
||||
return MsgPackError::Ok;
|
||||
}
|
||||
|
||||
MsgPackError readArray(JsonVariant &variant, size_t n) {
|
||||
JsonArray *array = new (_buffer) JsonArray(_buffer);
|
||||
if (!array) return MsgPackError::NoMemory;
|
||||
variant = array;
|
||||
return readArray(*array, n);
|
||||
}
|
||||
|
||||
MsgPackError readArray(JsonArray &array, size_t n) {
|
||||
if (_nestingLimit == 0) return MsgPackError::TooDeep;
|
||||
--_nestingLimit;
|
||||
for (; n; --n) {
|
||||
JsonVariant variant;
|
||||
MsgPackError err = parse(variant);
|
||||
if (err) return err;
|
||||
if (!array.add(variant)) return MsgPackError::NoMemory;
|
||||
}
|
||||
++_nestingLimit;
|
||||
return MsgPackError::Ok;
|
||||
}
|
||||
|
||||
MsgPackError readObject(JsonVariant &variant, size_t n) {
|
||||
JsonObject *object = new (_buffer) JsonObject(_buffer);
|
||||
if (!object) return MsgPackError::NoMemory;
|
||||
variant = object;
|
||||
return readObject(*object, n);
|
||||
}
|
||||
|
||||
MsgPackError readObject(JsonObject &object, size_t n) {
|
||||
if (_nestingLimit == 0) return MsgPackError::TooDeep;
|
||||
--_nestingLimit;
|
||||
for (; n; --n) {
|
||||
MsgPackError err;
|
||||
JsonVariant variant;
|
||||
err = parse(variant);
|
||||
if (err) return err;
|
||||
const char *key = variant.as<char *>();
|
||||
if (!key) return MsgPackError::NotSupported;
|
||||
err = parse(variant);
|
||||
if (err) return err;
|
||||
if (!object.set(key, variant)) return MsgPackError::NoMemory;
|
||||
}
|
||||
++_nestingLimit;
|
||||
return MsgPackError::Ok;
|
||||
}
|
||||
|
||||
JsonBuffer *_buffer;
|
||||
TReader _reader;
|
||||
TWriter _writer;
|
||||
uint8_t _nestingLimit;
|
||||
};
|
||||
|
||||
template <typename TJsonBuffer, typename TString, typename Enable = void>
|
||||
struct MsgPackDeserializerBuilder {
|
||||
typedef typename StringTraits<TString>::Reader InputReader;
|
||||
typedef MsgPackDeserializer<InputReader, TJsonBuffer &> TParser;
|
||||
|
||||
static TParser makeMsgPackDeserializer(TJsonBuffer *buffer, TString &json,
|
||||
uint8_t nestingLimit) {
|
||||
return TParser(buffer, InputReader(json), *buffer, nestingLimit);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TJsonBuffer, typename TChar>
|
||||
struct MsgPackDeserializerBuilder<
|
||||
TJsonBuffer, TChar *, typename EnableIf<!IsConst<TChar>::value>::type> {
|
||||
typedef typename StringTraits<TChar *>::Reader TReader;
|
||||
typedef StringWriter<TChar> TWriter;
|
||||
typedef MsgPackDeserializer<TReader, TWriter> TParser;
|
||||
|
||||
static TParser makeMsgPackDeserializer(TJsonBuffer *buffer, TChar *json,
|
||||
uint8_t nestingLimit) {
|
||||
return TParser(buffer, TReader(json), TWriter(json), nestingLimit);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TJsonBuffer, typename TString>
|
||||
inline typename MsgPackDeserializerBuilder<TJsonBuffer, TString>::TParser
|
||||
makeMsgPackDeserializer(TJsonBuffer *buffer, TString &json,
|
||||
uint8_t nestingLimit) {
|
||||
return MsgPackDeserializerBuilder<
|
||||
TJsonBuffer, TString>::makeMsgPackDeserializer(buffer, json,
|
||||
nestingLimit);
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -0,0 +1,67 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
class MsgPackError {
|
||||
public:
|
||||
enum Code { Ok, NotSupported, NoMemory, NotAnArray, NotAnObject, TooDeep };
|
||||
|
||||
MsgPackError() {}
|
||||
|
||||
MsgPackError(Code code) : _code(code) {}
|
||||
|
||||
operator bool() const {
|
||||
return _code != Ok;
|
||||
}
|
||||
|
||||
friend bool operator==(const MsgPackError& err, Code code) {
|
||||
return err._code == code;
|
||||
}
|
||||
|
||||
friend bool operator==(Code code, const MsgPackError& err) {
|
||||
return err._code == code;
|
||||
}
|
||||
|
||||
friend bool operator!=(const MsgPackError& err, Code code) {
|
||||
return err._code != code;
|
||||
}
|
||||
|
||||
friend bool operator!=(Code code, const MsgPackError& err) {
|
||||
return err._code != code;
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
switch (_code) {
|
||||
case Ok:
|
||||
return "Ok";
|
||||
case NotSupported:
|
||||
return "NotSupported";
|
||||
case NoMemory:
|
||||
return "NoMemory";
|
||||
case NotAnArray:
|
||||
return "NotAnArray";
|
||||
case NotAnObject:
|
||||
return "NotAnObject";
|
||||
case TooDeep:
|
||||
return "TooDeep";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Code _code;
|
||||
};
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STREAM
|
||||
inline std::ostream& operator<<(std::ostream& os, const MsgPackError& err) {
|
||||
os << err.c_str();
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace ArduinoJson
|
||||
@@ -0,0 +1,47 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <class T, T v>
|
||||
struct integral_constant {};
|
||||
|
||||
template <typename T>
|
||||
inline void swap(T& a, T& b) {
|
||||
T t(a);
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 8>) {
|
||||
swap(p[0], p[7]);
|
||||
swap(p[1], p[6]);
|
||||
swap(p[2], p[5]);
|
||||
swap(p[3], p[4]);
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 4>) {
|
||||
swap(p[0], p[3]);
|
||||
swap(p[1], p[2]);
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 2>) {
|
||||
swap(p[0], p[1]);
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t*, integral_constant<size_t, 1>) {}
|
||||
|
||||
template <typename T>
|
||||
inline void fixEndianess(T& value) {
|
||||
#if ARDUINOJSON_LITTLE_ENDIAN
|
||||
fixEndianess(reinterpret_cast<uint8_t*>(&value),
|
||||
integral_constant<size_t, sizeof(T)>());
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -0,0 +1,18 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
inline void doubleToFloat(const uint8_t d[8], uint8_t f[4]) {
|
||||
f[0] = uint8_t((d[0] & 0xC0) | (d[0] << 3 & 0x3f) | (d[1] >> 5));
|
||||
f[1] = uint8_t((d[1] << 3) | (d[2] >> 5));
|
||||
f[2] = uint8_t((d[2] << 3) | (d[3] >> 5));
|
||||
f[3] = uint8_t((d[3] << 3) | (d[4] >> 5));
|
||||
}
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
File renamed without changes.
+3
-3
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../StringTraits/StringTraits.hpp"
|
||||
#include "../Strings/StringTraits.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@@ -31,5 +31,5 @@ class DynamicStringBuilder {
|
||||
|
||||
TString &_str;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -5,7 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string.h> // for strcmp
|
||||
#include "./ctype.hpp"
|
||||
#include "../Polyfills/ctype.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@@ -34,5 +34,5 @@ inline bool isFloat(const char* s) {
|
||||
|
||||
return *s == '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./ctype.hpp"
|
||||
#include "../Polyfills/ctype.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@@ -15,5 +15,5 @@ inline bool isInteger(const char* s) {
|
||||
while (isdigit(*s)) s++;
|
||||
return *s == '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Polyfills/ctype.hpp"
|
||||
#include "../Polyfills/math.hpp"
|
||||
#include "../TypeTraits/FloatTraits.hpp"
|
||||
#include "./ctype.hpp"
|
||||
#include "./math.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@@ -86,5 +86,5 @@ inline T parseFloat(const char* s) {
|
||||
|
||||
return negative_result ? -result : result;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../Configuration.hpp"
|
||||
#include "./ctype.hpp"
|
||||
#include "../Polyfills/ctype.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
@@ -37,5 +37,5 @@ T parseInteger(const char *s) {
|
||||
|
||||
return negative_result ? T(~result + 1) : result;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Deserialization/JsonParser.hpp"
|
||||
#include "Json/Deserialization/JsonParser.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
// JsonError deserializeJson(TDestination& destination, TString json);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MsgPack/MsgPackDeserializer.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
// MsgPackError deserializeMsgPack(TDestination& destination, TString json);
|
||||
// TDestination = JsonArray, JsonObject, JsonVariant
|
||||
// TString = const std::string&, const String&
|
||||
template <typename TDestination, typename TString>
|
||||
typename Internals::EnableIf<!Internals::IsArray<TString>::value,
|
||||
MsgPackError>::type
|
||||
deserializeMsgPack(TDestination &destination, const TString &json,
|
||||
uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
|
||||
destination.clear();
|
||||
return Internals::makeMsgPackDeserializer(&destination.buffer(), json,
|
||||
nestingLimit)
|
||||
.parse(destination);
|
||||
}
|
||||
//
|
||||
// MsgPackError deserializeMsgPack(TDestination& destination, TString json);
|
||||
// TDestination = JsonArray, JsonObject, JsonVariant
|
||||
// TString = const char*, const char[N], const FlashStringHelper*
|
||||
template <typename TDestination, typename TString>
|
||||
MsgPackError deserializeMsgPack(
|
||||
TDestination &destination, TString *json,
|
||||
uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
|
||||
destination.clear();
|
||||
return Internals::makeMsgPackDeserializer(&destination.buffer(), json,
|
||||
nestingLimit)
|
||||
.parse(destination);
|
||||
}
|
||||
//
|
||||
// MsgPackError deserializeMsgPack(TDestination& destination, TString json);
|
||||
// TDestination = JsonArray, JsonObject, JsonVariant
|
||||
// TString = std::istream&, Stream&
|
||||
template <typename TDestination, typename TString>
|
||||
MsgPackError deserializeMsgPack(
|
||||
TDestination &destination, TString &json,
|
||||
uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
|
||||
destination.clear();
|
||||
return Internals::makeMsgPackDeserializer(&destination.buffer(), json,
|
||||
nestingLimit)
|
||||
.parse(destination);
|
||||
}
|
||||
} // namespace ArduinoJson
|
||||
Reference in new issue
Block a user